//#define LOCAL
#include <bits/stdc++.h>
#include <cassert>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,fma")
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
#define MAX 1010101
#define MAXQ 101010
#define INF 1'000'000'100
#define bb ' '
#define ln '\n'
#define Ln '\n'
#define MOD 1000000007
#define TC 1
#ifdef LOCAL
#define DEBUG(a) cout<<a
#else
#define DEBUG(...) 1234
#endif
#define B 1000
int A[MAX];
multiset<int> all[MAX];
multiset<int> upd[MAX];
int N, Q;
void prop(int id) {
all[id].clear();
int i;
for (i = id * B; i < min(N, (id + 1) * B); i++) {
upd[id].emplace(A[i]);
A[i] = *upd[id].begin();
upd[id].erase(upd[id].begin());
all[id].emplace(A[i]);
}
upd[id].clear();
}
signed main() {
ios::sync_with_stdio(false), cin.tie(0);
cin >> N >> Q;
int i;
for (i = 0; i < N; i++) cin >> A[i];
for (i = 0; i < N; i++) all[i / B].insert(A[i]);
auto f = [&](int l, int r, int x) {
int i;
i = l;
while (i <= r) {
int b = i / B;
if ((i % B == 0) && i + B - 1 <= r) {
//DEBUG("ii" << i << ln);
upd[b].insert(x);
if (upd[b].size() > B) upd[b].erase(upd[b].find(*upd[b].rbegin()));
all[b].insert(x);
x = *all[b].rbegin();
all[b].erase(all[b].find(x));
i += B;
//DEBUG('x' << x << bb);
}
else {
if (upd[b].size()) prop(b);
//DEBUG('i' << i << bb << A[i] << bb << x << ln);
if (A[i] > x) {
//for (auto x : all[b]) DEBUG('x' << x << bb);
//DEBUG("fuck" << ln);
//for (int i = B * b; i < B * (b + 1); i++) DEBUG(A[i] << bb);
//DEBUG(ln);
//DEBUG("asdf" << x << bb << A[i]);
all[b].insert(x);
all[b].erase(all[b].find(A[i]));
swap(A[i], x);
}
i++;
//DEBUG('y' << x << bb);
}
}
return x;
};
while (Q--) {
int l, r, x;
cin >> l >> r >> x;
l--;
r--;
if (l > r) {
x = f(l, N - 1, x);
x = f(0, r, x);
}
else x = f(l, r, x);
cout << x << ln;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
50 ms |
97116 KB |
Output is correct |
2 |
Correct |
47 ms |
97116 KB |
Output is correct |
3 |
Correct |
53 ms |
97112 KB |
Output is correct |
4 |
Correct |
66 ms |
97168 KB |
Output is correct |
5 |
Correct |
48 ms |
96964 KB |
Output is correct |
6 |
Correct |
51 ms |
95320 KB |
Output is correct |
7 |
Correct |
44 ms |
97116 KB |
Output is correct |
8 |
Correct |
57 ms |
97004 KB |
Output is correct |
9 |
Correct |
53 ms |
97168 KB |
Output is correct |
10 |
Correct |
49 ms |
97116 KB |
Output is correct |
11 |
Correct |
106 ms |
97116 KB |
Output is correct |
12 |
Correct |
107 ms |
97168 KB |
Output is correct |
13 |
Correct |
87 ms |
97116 KB |
Output is correct |
14 |
Correct |
75 ms |
97116 KB |
Output is correct |
15 |
Correct |
76 ms |
97116 KB |
Output is correct |
16 |
Correct |
28 ms |
97116 KB |
Output is correct |
17 |
Correct |
25 ms |
96856 KB |
Output is correct |
18 |
Correct |
27 ms |
96860 KB |
Output is correct |
19 |
Correct |
27 ms |
96860 KB |
Output is correct |
20 |
Correct |
26 ms |
96852 KB |
Output is correct |
21 |
Correct |
28 ms |
96860 KB |
Output is correct |
22 |
Correct |
27 ms |
96860 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7913 ms |
134648 KB |
Output is correct |
2 |
Correct |
8186 ms |
134740 KB |
Output is correct |
3 |
Correct |
10104 ms |
134484 KB |
Output is correct |
4 |
Correct |
7991 ms |
134740 KB |
Output is correct |
5 |
Correct |
5724 ms |
134740 KB |
Output is correct |
6 |
Correct |
9591 ms |
134824 KB |
Output is correct |
7 |
Correct |
9387 ms |
134788 KB |
Output is correct |
8 |
Correct |
9717 ms |
134788 KB |
Output is correct |
9 |
Correct |
6052 ms |
134588 KB |
Output is correct |
10 |
Correct |
5836 ms |
134632 KB |
Output is correct |
11 |
Correct |
6194 ms |
134736 KB |
Output is correct |
12 |
Correct |
7525 ms |
134740 KB |
Output is correct |
13 |
Correct |
7919 ms |
134620 KB |
Output is correct |
14 |
Correct |
8265 ms |
134812 KB |
Output is correct |
15 |
Correct |
9946 ms |
134864 KB |
Output is correct |
16 |
Correct |
8189 ms |
134896 KB |
Output is correct |
17 |
Correct |
7354 ms |
134684 KB |
Output is correct |
18 |
Correct |
9506 ms |
134724 KB |
Output is correct |
19 |
Correct |
9432 ms |
134672 KB |
Output is correct |
20 |
Correct |
8247 ms |
134900 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
50 ms |
97116 KB |
Output is correct |
2 |
Correct |
47 ms |
97116 KB |
Output is correct |
3 |
Correct |
53 ms |
97112 KB |
Output is correct |
4 |
Correct |
66 ms |
97168 KB |
Output is correct |
5 |
Correct |
48 ms |
96964 KB |
Output is correct |
6 |
Correct |
51 ms |
95320 KB |
Output is correct |
7 |
Correct |
44 ms |
97116 KB |
Output is correct |
8 |
Correct |
57 ms |
97004 KB |
Output is correct |
9 |
Correct |
53 ms |
97168 KB |
Output is correct |
10 |
Correct |
49 ms |
97116 KB |
Output is correct |
11 |
Correct |
106 ms |
97116 KB |
Output is correct |
12 |
Correct |
107 ms |
97168 KB |
Output is correct |
13 |
Correct |
87 ms |
97116 KB |
Output is correct |
14 |
Correct |
75 ms |
97116 KB |
Output is correct |
15 |
Correct |
76 ms |
97116 KB |
Output is correct |
16 |
Correct |
28 ms |
97116 KB |
Output is correct |
17 |
Correct |
25 ms |
96856 KB |
Output is correct |
18 |
Correct |
27 ms |
96860 KB |
Output is correct |
19 |
Correct |
27 ms |
96860 KB |
Output is correct |
20 |
Correct |
26 ms |
96852 KB |
Output is correct |
21 |
Correct |
28 ms |
96860 KB |
Output is correct |
22 |
Correct |
27 ms |
96860 KB |
Output is correct |
23 |
Correct |
7913 ms |
134648 KB |
Output is correct |
24 |
Correct |
8186 ms |
134740 KB |
Output is correct |
25 |
Correct |
10104 ms |
134484 KB |
Output is correct |
26 |
Correct |
7991 ms |
134740 KB |
Output is correct |
27 |
Correct |
5724 ms |
134740 KB |
Output is correct |
28 |
Correct |
9591 ms |
134824 KB |
Output is correct |
29 |
Correct |
9387 ms |
134788 KB |
Output is correct |
30 |
Correct |
9717 ms |
134788 KB |
Output is correct |
31 |
Correct |
6052 ms |
134588 KB |
Output is correct |
32 |
Correct |
5836 ms |
134632 KB |
Output is correct |
33 |
Correct |
6194 ms |
134736 KB |
Output is correct |
34 |
Correct |
7525 ms |
134740 KB |
Output is correct |
35 |
Correct |
7919 ms |
134620 KB |
Output is correct |
36 |
Correct |
8265 ms |
134812 KB |
Output is correct |
37 |
Correct |
9946 ms |
134864 KB |
Output is correct |
38 |
Correct |
8189 ms |
134896 KB |
Output is correct |
39 |
Correct |
7354 ms |
134684 KB |
Output is correct |
40 |
Correct |
9506 ms |
134724 KB |
Output is correct |
41 |
Correct |
9432 ms |
134672 KB |
Output is correct |
42 |
Correct |
8247 ms |
134900 KB |
Output is correct |
43 |
Correct |
8734 ms |
122520 KB |
Output is correct |
44 |
Correct |
10500 ms |
122652 KB |
Output is correct |
45 |
Execution timed out |
12082 ms |
119176 KB |
Time limit exceeded |
46 |
Halted |
0 ms |
0 KB |
- |