#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define pb push_back
#define ff first
#define ss second
#define ins insert
const ll inf = numeric_limits<ll> :: max();
struct STB{
vector<ll> a;
// a[i] += x (l <= i <= r)
// a[i] = max(a[i], x) (l <= i <= r)
// ? a[i]
int n;
STB(int ns){
n = ns;
a.resize(n + 1);
}
void add(int l, int r, ll x){
for (int i = l; i <= r; i++){
a[i] += x;
}
}
void chmax(int l, int r, ll x){
for (int i = l; i <= r; i++){
a[i] = max(a[i], x);
}
}
ll get(int p){
return a[p];
}
};
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, m, q; cin>>n>>m>>q;
STB C(n);
const int S = n;
const int sz = (int) ceil(1.0 * n / S) - 1;
vector<int> st[n + 1], st1[sz + 5];
vector<ll> pr[n + 1], pr1[sz + 5];
vector<int> bc(n + 1);
int i = 1, j = S, k = 0;
while (i <= n){
while (i <= j) bc[i++] = k;
j = min(n, j + S);
k++;
}
vector<int> col(q + 1);
map<int, bool> mp;
for (int tt = 1; tt <= q; tt++){
int type; cin>>type;
if (type == 1){
int l, r, c, k; cin>>l>>r>>c>>k;
col[tt] = c;
mp[tt] = 1;
C.add(l, r, k);
int bl = bc[l] + 1, br = bc[r] - 1;
if (bl > br){
for (int i = l; i <= r; i++){
st[i].pb(tt);
if (pr[i].empty()) pr[i].pb(k);
else pr[i].pb(pr[i].back() + k);
}
continue;
}
for (int i = bl; i <= br; i++){
st1[i].pb(tt);
if (pr1[i].empty()) pr1[i].pb(k);
else pr1[i].pb(pr1[i].back() + k);
}
for (int i = l; i <= S * bl; i++){
st[i].pb(tt);
if (pr[i].empty()) pr[i].pb(k);
else pr[i].pb(pr[i].back() + k);
}
for (int i = S * (br + 1) + 1; i <= r; i++){
st[i].pb(tt);
if (pr[i].empty()) pr[i].pb(k);
else pr[i].pb(pr[i].back() + k);
}
}
else if (type == 2){
int l, r, k; cin>>l>>r>>k;
C.add(l, r, -k);
C.chmax(1, n, 0);
}
else {
int a; ll b; cin>>a>>b;
ll v = C.get(a);
if (b > v){
cout<<0<<"\n";
continue;
}
b -= v;
if (!pr1[bc[a]].empty()) b += pr1[bc[a]].back();
if (!pr[a].empty()) b += pr[a].back();
auto low = [&](vector<int>& x, int t){
if (x.empty() || x[0] > t) return -1;
int l = 0, r = (int) x.size() - 1;
while (l + 1 < r){
int m = (l + r) / 2;
if (x[m] <= t){
l = m;
}
else {
r = m - 1;
}
}
if (x[r] <= t) l = r;
return l;
};
auto check = [&](int m){
int j1 = low(st1[bc[a]], m);
int j2 = low(st[a], m);
ll val = 0;
if (j1 >= 0) val += pr1[bc[a]][j1];
if (j2 >= 0) val += pr[a][j2];
return (val >= b);
};
int l = 1, r = tt;
while (l + 1 < r){
int m = (l + r) / 2;
if (check(m)){
r = m;
}
else {
l = m + 1;
}
}
if (check(l)) r = l;
if (mp.find(r) == mp.end()){
while (true){
l++;
}
}
cout<<col[r]<<"\n";
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
4700 KB |
Output is correct |
2 |
Correct |
9 ms |
9052 KB |
Output is correct |
3 |
Correct |
11 ms |
10652 KB |
Output is correct |
4 |
Correct |
18 ms |
19548 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
14 ms |
14172 KB |
Output is correct |
8 |
Correct |
15 ms |
13660 KB |
Output is correct |
9 |
Correct |
14 ms |
13660 KB |
Output is correct |
10 |
Correct |
16 ms |
14684 KB |
Output is correct |
11 |
Correct |
16 ms |
15136 KB |
Output is correct |
12 |
Correct |
16 ms |
14276 KB |
Output is correct |
13 |
Correct |
24 ms |
22480 KB |
Output is correct |
14 |
Correct |
30 ms |
24660 KB |
Output is correct |
15 |
Correct |
16 ms |
12124 KB |
Output is correct |
16 |
Correct |
24 ms |
24412 KB |
Output is correct |
17 |
Correct |
7 ms |
7260 KB |
Output is correct |
18 |
Correct |
13 ms |
10956 KB |
Output is correct |
19 |
Correct |
2 ms |
856 KB |
Output is correct |
20 |
Correct |
2 ms |
860 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
4700 KB |
Output is correct |
2 |
Correct |
9 ms |
9052 KB |
Output is correct |
3 |
Correct |
11 ms |
10652 KB |
Output is correct |
4 |
Correct |
18 ms |
19548 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
14 ms |
14172 KB |
Output is correct |
8 |
Correct |
15 ms |
13660 KB |
Output is correct |
9 |
Correct |
14 ms |
13660 KB |
Output is correct |
10 |
Correct |
16 ms |
14684 KB |
Output is correct |
11 |
Correct |
16 ms |
15136 KB |
Output is correct |
12 |
Correct |
16 ms |
14276 KB |
Output is correct |
13 |
Correct |
24 ms |
22480 KB |
Output is correct |
14 |
Correct |
30 ms |
24660 KB |
Output is correct |
15 |
Correct |
16 ms |
12124 KB |
Output is correct |
16 |
Correct |
24 ms |
24412 KB |
Output is correct |
17 |
Correct |
7 ms |
7260 KB |
Output is correct |
18 |
Correct |
13 ms |
10956 KB |
Output is correct |
19 |
Correct |
2 ms |
856 KB |
Output is correct |
20 |
Correct |
2 ms |
860 KB |
Output is correct |
21 |
Correct |
9 ms |
8196 KB |
Output is correct |
22 |
Correct |
10 ms |
9052 KB |
Output is correct |
23 |
Correct |
13 ms |
12892 KB |
Output is correct |
24 |
Correct |
19 ms |
19448 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
524 KB |
Output is correct |
27 |
Correct |
14 ms |
11612 KB |
Output is correct |
28 |
Correct |
16 ms |
14696 KB |
Output is correct |
29 |
Correct |
16 ms |
14684 KB |
Output is correct |
30 |
Correct |
16 ms |
13932 KB |
Output is correct |
31 |
Correct |
14 ms |
11356 KB |
Output is correct |
32 |
Correct |
13 ms |
11356 KB |
Output is correct |
33 |
Correct |
21 ms |
20388 KB |
Output is correct |
34 |
Correct |
29 ms |
24748 KB |
Output is correct |
35 |
Correct |
18 ms |
18776 KB |
Output is correct |
36 |
Correct |
25 ms |
24440 KB |
Output is correct |
37 |
Correct |
1 ms |
780 KB |
Output is correct |
38 |
Correct |
1 ms |
860 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
738 ms |
9680 KB |
Output is correct |
2 |
Correct |
567 ms |
12884 KB |
Output is correct |
3 |
Correct |
722 ms |
12884 KB |
Output is correct |
4 |
Correct |
750 ms |
12884 KB |
Output is correct |
5 |
Correct |
666 ms |
15648 KB |
Output is correct |
6 |
Correct |
580 ms |
15628 KB |
Output is correct |
7 |
Correct |
17 ms |
2648 KB |
Output is correct |
8 |
Correct |
17 ms |
2908 KB |
Output is correct |
9 |
Correct |
835 ms |
11092 KB |
Output is correct |
10 |
Correct |
946 ms |
11088 KB |
Output is correct |
11 |
Correct |
918 ms |
11208 KB |
Output is correct |
12 |
Correct |
945 ms |
11212 KB |
Output is correct |
13 |
Correct |
221 ms |
10784 KB |
Output is correct |
14 |
Correct |
320 ms |
13520 KB |
Output is correct |
15 |
Correct |
64 ms |
14420 KB |
Output is correct |
16 |
Correct |
82 ms |
16480 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
941 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
4700 KB |
Output is correct |
2 |
Correct |
9 ms |
9052 KB |
Output is correct |
3 |
Correct |
11 ms |
10652 KB |
Output is correct |
4 |
Correct |
18 ms |
19548 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
14 ms |
14172 KB |
Output is correct |
8 |
Correct |
15 ms |
13660 KB |
Output is correct |
9 |
Correct |
14 ms |
13660 KB |
Output is correct |
10 |
Correct |
16 ms |
14684 KB |
Output is correct |
11 |
Correct |
16 ms |
15136 KB |
Output is correct |
12 |
Correct |
16 ms |
14276 KB |
Output is correct |
13 |
Correct |
24 ms |
22480 KB |
Output is correct |
14 |
Correct |
30 ms |
24660 KB |
Output is correct |
15 |
Correct |
16 ms |
12124 KB |
Output is correct |
16 |
Correct |
24 ms |
24412 KB |
Output is correct |
17 |
Correct |
7 ms |
7260 KB |
Output is correct |
18 |
Correct |
13 ms |
10956 KB |
Output is correct |
19 |
Correct |
2 ms |
856 KB |
Output is correct |
20 |
Correct |
2 ms |
860 KB |
Output is correct |
21 |
Correct |
738 ms |
9680 KB |
Output is correct |
22 |
Correct |
567 ms |
12884 KB |
Output is correct |
23 |
Correct |
722 ms |
12884 KB |
Output is correct |
24 |
Correct |
750 ms |
12884 KB |
Output is correct |
25 |
Correct |
666 ms |
15648 KB |
Output is correct |
26 |
Correct |
580 ms |
15628 KB |
Output is correct |
27 |
Correct |
17 ms |
2648 KB |
Output is correct |
28 |
Correct |
17 ms |
2908 KB |
Output is correct |
29 |
Correct |
835 ms |
11092 KB |
Output is correct |
30 |
Correct |
946 ms |
11088 KB |
Output is correct |
31 |
Correct |
918 ms |
11208 KB |
Output is correct |
32 |
Correct |
945 ms |
11212 KB |
Output is correct |
33 |
Correct |
221 ms |
10784 KB |
Output is correct |
34 |
Correct |
320 ms |
13520 KB |
Output is correct |
35 |
Correct |
64 ms |
14420 KB |
Output is correct |
36 |
Correct |
82 ms |
16480 KB |
Output is correct |
37 |
Runtime error |
618 ms |
524288 KB |
Execution killed with signal 9 |
38 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
607 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
4700 KB |
Output is correct |
2 |
Correct |
9 ms |
9052 KB |
Output is correct |
3 |
Correct |
11 ms |
10652 KB |
Output is correct |
4 |
Correct |
18 ms |
19548 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
14 ms |
14172 KB |
Output is correct |
8 |
Correct |
15 ms |
13660 KB |
Output is correct |
9 |
Correct |
14 ms |
13660 KB |
Output is correct |
10 |
Correct |
16 ms |
14684 KB |
Output is correct |
11 |
Correct |
16 ms |
15136 KB |
Output is correct |
12 |
Correct |
16 ms |
14276 KB |
Output is correct |
13 |
Correct |
24 ms |
22480 KB |
Output is correct |
14 |
Correct |
30 ms |
24660 KB |
Output is correct |
15 |
Correct |
16 ms |
12124 KB |
Output is correct |
16 |
Correct |
24 ms |
24412 KB |
Output is correct |
17 |
Correct |
7 ms |
7260 KB |
Output is correct |
18 |
Correct |
13 ms |
10956 KB |
Output is correct |
19 |
Correct |
2 ms |
856 KB |
Output is correct |
20 |
Correct |
2 ms |
860 KB |
Output is correct |
21 |
Correct |
9 ms |
8196 KB |
Output is correct |
22 |
Correct |
10 ms |
9052 KB |
Output is correct |
23 |
Correct |
13 ms |
12892 KB |
Output is correct |
24 |
Correct |
19 ms |
19448 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
524 KB |
Output is correct |
27 |
Correct |
14 ms |
11612 KB |
Output is correct |
28 |
Correct |
16 ms |
14696 KB |
Output is correct |
29 |
Correct |
16 ms |
14684 KB |
Output is correct |
30 |
Correct |
16 ms |
13932 KB |
Output is correct |
31 |
Correct |
14 ms |
11356 KB |
Output is correct |
32 |
Correct |
13 ms |
11356 KB |
Output is correct |
33 |
Correct |
21 ms |
20388 KB |
Output is correct |
34 |
Correct |
29 ms |
24748 KB |
Output is correct |
35 |
Correct |
18 ms |
18776 KB |
Output is correct |
36 |
Correct |
25 ms |
24440 KB |
Output is correct |
37 |
Correct |
1 ms |
780 KB |
Output is correct |
38 |
Correct |
1 ms |
860 KB |
Output is correct |
39 |
Correct |
738 ms |
9680 KB |
Output is correct |
40 |
Correct |
567 ms |
12884 KB |
Output is correct |
41 |
Correct |
722 ms |
12884 KB |
Output is correct |
42 |
Correct |
750 ms |
12884 KB |
Output is correct |
43 |
Correct |
666 ms |
15648 KB |
Output is correct |
44 |
Correct |
580 ms |
15628 KB |
Output is correct |
45 |
Correct |
17 ms |
2648 KB |
Output is correct |
46 |
Correct |
17 ms |
2908 KB |
Output is correct |
47 |
Correct |
835 ms |
11092 KB |
Output is correct |
48 |
Correct |
946 ms |
11088 KB |
Output is correct |
49 |
Correct |
918 ms |
11208 KB |
Output is correct |
50 |
Correct |
945 ms |
11212 KB |
Output is correct |
51 |
Correct |
221 ms |
10784 KB |
Output is correct |
52 |
Correct |
320 ms |
13520 KB |
Output is correct |
53 |
Correct |
64 ms |
14420 KB |
Output is correct |
54 |
Correct |
82 ms |
16480 KB |
Output is correct |
55 |
Runtime error |
618 ms |
524288 KB |
Execution killed with signal 9 |
56 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
4700 KB |
Output is correct |
2 |
Correct |
9 ms |
9052 KB |
Output is correct |
3 |
Correct |
11 ms |
10652 KB |
Output is correct |
4 |
Correct |
18 ms |
19548 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
14 ms |
14172 KB |
Output is correct |
8 |
Correct |
15 ms |
13660 KB |
Output is correct |
9 |
Correct |
14 ms |
13660 KB |
Output is correct |
10 |
Correct |
16 ms |
14684 KB |
Output is correct |
11 |
Correct |
16 ms |
15136 KB |
Output is correct |
12 |
Correct |
16 ms |
14276 KB |
Output is correct |
13 |
Correct |
24 ms |
22480 KB |
Output is correct |
14 |
Correct |
30 ms |
24660 KB |
Output is correct |
15 |
Correct |
16 ms |
12124 KB |
Output is correct |
16 |
Correct |
24 ms |
24412 KB |
Output is correct |
17 |
Correct |
7 ms |
7260 KB |
Output is correct |
18 |
Correct |
13 ms |
10956 KB |
Output is correct |
19 |
Correct |
2 ms |
856 KB |
Output is correct |
20 |
Correct |
2 ms |
860 KB |
Output is correct |
21 |
Correct |
9 ms |
8196 KB |
Output is correct |
22 |
Correct |
10 ms |
9052 KB |
Output is correct |
23 |
Correct |
13 ms |
12892 KB |
Output is correct |
24 |
Correct |
19 ms |
19448 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
524 KB |
Output is correct |
27 |
Correct |
14 ms |
11612 KB |
Output is correct |
28 |
Correct |
16 ms |
14696 KB |
Output is correct |
29 |
Correct |
16 ms |
14684 KB |
Output is correct |
30 |
Correct |
16 ms |
13932 KB |
Output is correct |
31 |
Correct |
14 ms |
11356 KB |
Output is correct |
32 |
Correct |
13 ms |
11356 KB |
Output is correct |
33 |
Correct |
21 ms |
20388 KB |
Output is correct |
34 |
Correct |
29 ms |
24748 KB |
Output is correct |
35 |
Correct |
18 ms |
18776 KB |
Output is correct |
36 |
Correct |
25 ms |
24440 KB |
Output is correct |
37 |
Correct |
1 ms |
780 KB |
Output is correct |
38 |
Correct |
1 ms |
860 KB |
Output is correct |
39 |
Correct |
738 ms |
9680 KB |
Output is correct |
40 |
Correct |
567 ms |
12884 KB |
Output is correct |
41 |
Correct |
722 ms |
12884 KB |
Output is correct |
42 |
Correct |
750 ms |
12884 KB |
Output is correct |
43 |
Correct |
666 ms |
15648 KB |
Output is correct |
44 |
Correct |
580 ms |
15628 KB |
Output is correct |
45 |
Correct |
17 ms |
2648 KB |
Output is correct |
46 |
Correct |
17 ms |
2908 KB |
Output is correct |
47 |
Correct |
835 ms |
11092 KB |
Output is correct |
48 |
Correct |
946 ms |
11088 KB |
Output is correct |
49 |
Correct |
918 ms |
11208 KB |
Output is correct |
50 |
Correct |
945 ms |
11212 KB |
Output is correct |
51 |
Correct |
221 ms |
10784 KB |
Output is correct |
52 |
Correct |
320 ms |
13520 KB |
Output is correct |
53 |
Correct |
64 ms |
14420 KB |
Output is correct |
54 |
Correct |
82 ms |
16480 KB |
Output is correct |
55 |
Runtime error |
941 ms |
524288 KB |
Execution killed with signal 9 |
56 |
Halted |
0 ms |
0 KB |
- |