题目链接:传送门
做完这个题感觉我是个沙雕
在越做越麻烦的道路上一去不复返
我真傻,
真的
(会有大量冗余变量)
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <complex>
#include <algorithm>
#include <climits>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#define
#define
using namespace std;
typedef long long ll;
struct node {
int l, r, mx;
}tree[A];
int n, m, w[A], a, b;
struct word {
string s;
int id;
friend bool operator < (const word a, const word b) {
return a.s > b.s;
}
}e[A], t[A], tt[A], ttt[A];
void build(int k, int l, int r) {
tree[k].l = l; tree[k].r = r;
if (l == r) {
tree[k].mx = w[l];
return;
}
int m = (l + r) >> 1;
build(k << 1, l, m);
build(k << 1 | 1, m + 1, r);
tree[k].mx = min(tree[k << 1].mx, tree[k << 1 | 1].mx);
}
int ask(int k, int l, int r) {
if (tree[k].l >= l and tree[k].r <= r) return tree[k].mx;
int m = (tree[k].l + tree[k].r) >> 1, ans = 0x3f3f3f3f;
if (l <= m) ans = min(ans, ask(k << 1 , l, r));
if (r > m) ans = min(ans, ask(k << 1 | 1, l, r));
return ans;
}
int main(int argc, char const *argv[]) {
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> e[i].s; tt[i].s = e[i].s; tt[i].id = i; ttt[i] = tt[i];
transform(e[i].s.begin(), e[i].s.end(), e[i].s.begin(), ::tolower);
e[i].id = i, t[i] = e[i];
}
sort(t + 1, t + n + 1);
for (int i = 1; i <= n; i++) tt[i] = ttt[t[i].id];
for (int i = 1; i <= n; i++) w[t[i].id] = i;
build(1, 1, n);
while (m--) {
cin >> a >> b;
cout << tt[ask(1, a, b)].s << endl;
}
}