#include <bits/stdc++.h>
using namespace std;
struct aaa {
int t, c;
long long k;
};
const int MAX_N = 3e5;
int group[MAX_N];
struct SegTree {
struct info {
long long tot, sum, minn;
info operator+( info &x ) {
info ans;
ans.tot = tot + x.tot;
ans.minn = min( minn, sum + x.minn );
ans.sum = sum + x.sum;
return ans;
}
};
info lazy[4 * MAX_N];
long long size[4 * MAX_N];
vector<aaa> q[4 * MAX_N];
void propag( int v, int l, int r ) {
if ( l != r ) {
lazy[v * 2 + 1] = lazy[v * 2 + 1] + lazy[v];
lazy[v * 2 + 2] = lazy[v * 2 + 2] + lazy[v];
lazy[v] = { 0, 0 };
}
}
void init( int v, int l, int r ) {
q[v].push_back( { -1, 0, 0 } );
if ( l == r )
return;
int mid = (l + r) / 2;
init( v * 2 + 1, l, mid );
init( v * 2 + 2, mid + 1, r );
}
void update( int v, int l, int r, int lu, int ru, int k, int c, int t ) {
propag( v, l, r );
if ( l > ru || r < lu )
return;
if ( lu <= l && r <= ru ) {
if ( k > 0 ) {
size[v] += k;
q[v].push_back( { t, c, size[v] } );
}
info add = { max( k, 0 ), k, min( k, 0 ) };
lazy[v] = lazy[v] + add;
propag( v, l, r );
return;
}
int mid = (l + r) / 2;
update( v * 2 + 1, l, mid, lu, ru, k, c, t );
update( v * 2 + 2, mid + 1, r, lu, ru, k, c, t );
}
vector<int> ans;
long long query( int v, int l, int r, int p ) {
if ( v == 0 )
ans.clear();
ans.push_back( v );
propag( v, l, r );
if ( l == r )
return lazy[v].tot - (lazy[v].sum - lazy[v].minn);
int mid = (l + r) / 2;
if ( p <= mid )
return query( v * 2 + 1, l, mid, p );
return query( v * 2 + 2, mid + 1, r, p );
}
} qs;
signed main() {
ios_base::sync_with_stdio( false );
cin.tie( NULL );
cout.tie( NULL );
int n, m, q;
cin >> n >> m >> q;
qs.init( 0, 1, n );
for ( int t = 0; t < q; t++ ) {
int type;
cin >> type;
if ( type == 1 ) {
int l, r, c, k;
cin >> l >> r >> c >> k;
qs.update( 0, 1, n, l, r, k, c, t );
group[t] = c;
} else if ( type == 2 ) {
int l, r, k;
cin >> l >> r >> k;
qs.update( 0, 1, n, l, r, -k, 0, t );
} else {
int p;
long long x;
cin >> p >> x;
x += qs.query( 0, 1, n, p );
vector<int> vert = qs.ans;
int l = -1, r = t;
while ( r - l > 1 ) {
int mid = (l + r) / 2;
int k = 0;
for ( int v: vert ) {
int lp = 0, rp = qs.q[v].size();
while ( rp - lp > 1 ) {
int mp = (lp + rp) / 2;
if ( qs.q[v][mp].t > mid )
rp = mp;
else
lp = mp;
}
k += qs.q[v][lp].k;
}
if ( k >= x )
r = mid;
else
l = mid;
}
cout << group[r] << "\n";
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
29528 KB |
Output is correct |
2 |
Correct |
9 ms |
29532 KB |
Output is correct |
3 |
Correct |
8 ms |
29532 KB |
Output is correct |
4 |
Correct |
11 ms |
29620 KB |
Output is correct |
5 |
Correct |
7 ms |
29248 KB |
Output is correct |
6 |
Correct |
7 ms |
29016 KB |
Output is correct |
7 |
Correct |
9 ms |
29540 KB |
Output is correct |
8 |
Correct |
10 ms |
29788 KB |
Output is correct |
9 |
Correct |
9 ms |
29660 KB |
Output is correct |
10 |
Correct |
9 ms |
29640 KB |
Output is correct |
11 |
Correct |
9 ms |
29460 KB |
Output is correct |
12 |
Correct |
9 ms |
29528 KB |
Output is correct |
13 |
Correct |
7 ms |
29464 KB |
Output is correct |
14 |
Correct |
8 ms |
29276 KB |
Output is correct |
15 |
Correct |
8 ms |
29532 KB |
Output is correct |
16 |
Correct |
8 ms |
29532 KB |
Output is correct |
17 |
Correct |
8 ms |
29396 KB |
Output is correct |
18 |
Correct |
9 ms |
29532 KB |
Output is correct |
19 |
Correct |
8 ms |
29532 KB |
Output is correct |
20 |
Correct |
8 ms |
29532 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
29528 KB |
Output is correct |
2 |
Correct |
9 ms |
29532 KB |
Output is correct |
3 |
Correct |
8 ms |
29532 KB |
Output is correct |
4 |
Correct |
11 ms |
29620 KB |
Output is correct |
5 |
Correct |
7 ms |
29248 KB |
Output is correct |
6 |
Correct |
7 ms |
29016 KB |
Output is correct |
7 |
Correct |
9 ms |
29540 KB |
Output is correct |
8 |
Correct |
10 ms |
29788 KB |
Output is correct |
9 |
Correct |
9 ms |
29660 KB |
Output is correct |
10 |
Correct |
9 ms |
29640 KB |
Output is correct |
11 |
Correct |
9 ms |
29460 KB |
Output is correct |
12 |
Correct |
9 ms |
29528 KB |
Output is correct |
13 |
Correct |
7 ms |
29464 KB |
Output is correct |
14 |
Correct |
8 ms |
29276 KB |
Output is correct |
15 |
Correct |
8 ms |
29532 KB |
Output is correct |
16 |
Correct |
8 ms |
29532 KB |
Output is correct |
17 |
Correct |
8 ms |
29396 KB |
Output is correct |
18 |
Correct |
9 ms |
29532 KB |
Output is correct |
19 |
Correct |
8 ms |
29532 KB |
Output is correct |
20 |
Correct |
8 ms |
29532 KB |
Output is correct |
21 |
Incorrect |
10 ms |
29528 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
79 ms |
40476 KB |
Output is correct |
2 |
Correct |
85 ms |
41136 KB |
Output is correct |
3 |
Correct |
103 ms |
40788 KB |
Output is correct |
4 |
Correct |
90 ms |
40888 KB |
Output is correct |
5 |
Correct |
101 ms |
42004 KB |
Output is correct |
6 |
Correct |
110 ms |
41956 KB |
Output is correct |
7 |
Correct |
43 ms |
30648 KB |
Output is correct |
8 |
Correct |
50 ms |
30724 KB |
Output is correct |
9 |
Correct |
82 ms |
40520 KB |
Output is correct |
10 |
Correct |
93 ms |
40656 KB |
Output is correct |
11 |
Correct |
88 ms |
40532 KB |
Output is correct |
12 |
Correct |
81 ms |
40528 KB |
Output is correct |
13 |
Correct |
73 ms |
39560 KB |
Output is correct |
14 |
Correct |
87 ms |
41348 KB |
Output is correct |
15 |
Correct |
80 ms |
41300 KB |
Output is correct |
16 |
Correct |
95 ms |
42676 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1041 ms |
91368 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
29528 KB |
Output is correct |
2 |
Correct |
9 ms |
29532 KB |
Output is correct |
3 |
Correct |
8 ms |
29532 KB |
Output is correct |
4 |
Correct |
11 ms |
29620 KB |
Output is correct |
5 |
Correct |
7 ms |
29248 KB |
Output is correct |
6 |
Correct |
7 ms |
29016 KB |
Output is correct |
7 |
Correct |
9 ms |
29540 KB |
Output is correct |
8 |
Correct |
10 ms |
29788 KB |
Output is correct |
9 |
Correct |
9 ms |
29660 KB |
Output is correct |
10 |
Correct |
9 ms |
29640 KB |
Output is correct |
11 |
Correct |
9 ms |
29460 KB |
Output is correct |
12 |
Correct |
9 ms |
29528 KB |
Output is correct |
13 |
Correct |
7 ms |
29464 KB |
Output is correct |
14 |
Correct |
8 ms |
29276 KB |
Output is correct |
15 |
Correct |
8 ms |
29532 KB |
Output is correct |
16 |
Correct |
8 ms |
29532 KB |
Output is correct |
17 |
Correct |
8 ms |
29396 KB |
Output is correct |
18 |
Correct |
9 ms |
29532 KB |
Output is correct |
19 |
Correct |
8 ms |
29532 KB |
Output is correct |
20 |
Correct |
8 ms |
29532 KB |
Output is correct |
21 |
Correct |
79 ms |
40476 KB |
Output is correct |
22 |
Correct |
85 ms |
41136 KB |
Output is correct |
23 |
Correct |
103 ms |
40788 KB |
Output is correct |
24 |
Correct |
90 ms |
40888 KB |
Output is correct |
25 |
Correct |
101 ms |
42004 KB |
Output is correct |
26 |
Correct |
110 ms |
41956 KB |
Output is correct |
27 |
Correct |
43 ms |
30648 KB |
Output is correct |
28 |
Correct |
50 ms |
30724 KB |
Output is correct |
29 |
Correct |
82 ms |
40520 KB |
Output is correct |
30 |
Correct |
93 ms |
40656 KB |
Output is correct |
31 |
Correct |
88 ms |
40532 KB |
Output is correct |
32 |
Correct |
81 ms |
40528 KB |
Output is correct |
33 |
Correct |
73 ms |
39560 KB |
Output is correct |
34 |
Correct |
87 ms |
41348 KB |
Output is correct |
35 |
Correct |
80 ms |
41300 KB |
Output is correct |
36 |
Correct |
95 ms |
42676 KB |
Output is correct |
37 |
Correct |
197 ms |
44424 KB |
Output is correct |
38 |
Correct |
169 ms |
46912 KB |
Output is correct |
39 |
Correct |
32 ms |
30484 KB |
Output is correct |
40 |
Correct |
44 ms |
30552 KB |
Output is correct |
41 |
Correct |
195 ms |
46800 KB |
Output is correct |
42 |
Correct |
202 ms |
47088 KB |
Output is correct |
43 |
Correct |
199 ms |
46772 KB |
Output is correct |
44 |
Correct |
196 ms |
46652 KB |
Output is correct |
45 |
Correct |
199 ms |
46912 KB |
Output is correct |
46 |
Correct |
192 ms |
46900 KB |
Output is correct |
47 |
Correct |
72 ms |
37836 KB |
Output is correct |
48 |
Correct |
134 ms |
46600 KB |
Output is correct |
49 |
Correct |
114 ms |
42724 KB |
Output is correct |
50 |
Correct |
141 ms |
45656 KB |
Output is correct |
51 |
Correct |
177 ms |
47184 KB |
Output is correct |
52 |
Correct |
178 ms |
47176 KB |
Output is correct |
53 |
Correct |
70 ms |
40860 KB |
Output is correct |
54 |
Correct |
124 ms |
42516 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
256 ms |
47956 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
29528 KB |
Output is correct |
2 |
Correct |
9 ms |
29532 KB |
Output is correct |
3 |
Correct |
8 ms |
29532 KB |
Output is correct |
4 |
Correct |
11 ms |
29620 KB |
Output is correct |
5 |
Correct |
7 ms |
29248 KB |
Output is correct |
6 |
Correct |
7 ms |
29016 KB |
Output is correct |
7 |
Correct |
9 ms |
29540 KB |
Output is correct |
8 |
Correct |
10 ms |
29788 KB |
Output is correct |
9 |
Correct |
9 ms |
29660 KB |
Output is correct |
10 |
Correct |
9 ms |
29640 KB |
Output is correct |
11 |
Correct |
9 ms |
29460 KB |
Output is correct |
12 |
Correct |
9 ms |
29528 KB |
Output is correct |
13 |
Correct |
7 ms |
29464 KB |
Output is correct |
14 |
Correct |
8 ms |
29276 KB |
Output is correct |
15 |
Correct |
8 ms |
29532 KB |
Output is correct |
16 |
Correct |
8 ms |
29532 KB |
Output is correct |
17 |
Correct |
8 ms |
29396 KB |
Output is correct |
18 |
Correct |
9 ms |
29532 KB |
Output is correct |
19 |
Correct |
8 ms |
29532 KB |
Output is correct |
20 |
Correct |
8 ms |
29532 KB |
Output is correct |
21 |
Incorrect |
10 ms |
29528 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
29528 KB |
Output is correct |
2 |
Correct |
9 ms |
29532 KB |
Output is correct |
3 |
Correct |
8 ms |
29532 KB |
Output is correct |
4 |
Correct |
11 ms |
29620 KB |
Output is correct |
5 |
Correct |
7 ms |
29248 KB |
Output is correct |
6 |
Correct |
7 ms |
29016 KB |
Output is correct |
7 |
Correct |
9 ms |
29540 KB |
Output is correct |
8 |
Correct |
10 ms |
29788 KB |
Output is correct |
9 |
Correct |
9 ms |
29660 KB |
Output is correct |
10 |
Correct |
9 ms |
29640 KB |
Output is correct |
11 |
Correct |
9 ms |
29460 KB |
Output is correct |
12 |
Correct |
9 ms |
29528 KB |
Output is correct |
13 |
Correct |
7 ms |
29464 KB |
Output is correct |
14 |
Correct |
8 ms |
29276 KB |
Output is correct |
15 |
Correct |
8 ms |
29532 KB |
Output is correct |
16 |
Correct |
8 ms |
29532 KB |
Output is correct |
17 |
Correct |
8 ms |
29396 KB |
Output is correct |
18 |
Correct |
9 ms |
29532 KB |
Output is correct |
19 |
Correct |
8 ms |
29532 KB |
Output is correct |
20 |
Correct |
8 ms |
29532 KB |
Output is correct |
21 |
Incorrect |
10 ms |
29528 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |