Submission #38421598
Source Code Expand
#include <bits/stdc++.h>
#define st first
#define nd second
#define db double
#define re register
#define pb push_back
#define mk make_pair
#define int long long
#define ldb long double
#define pii pair<int, int>
#define ull unsigned long long
#define mst(a, b) memset(a, b, sizeof(a))
using namespace std;
const int N = 2e5 + 10, lim = 1e9, INF = 2e9;
inline int read()
{
int s = 0, w = 1;
char ch = getchar();
while(ch < '0' || ch > '9') { if(ch == '-') w *= -1; ch = getchar(); }
while(ch >= '0' && ch <= '9') s = s * 10 + ch - '0', ch = getchar();
return s * w;
}
int n, Q, rt;
int a[N], b[N];
#define mid ((l + r) >> 1)
struct SegmentTree{
int tot, ls[100 * N], rs[100 * N];
int cnt[100 * N], val[100 * N];
inline void update(int &k, int l, int r, int x, int v){
if(!k) k = ++tot, cnt[k] = val[k] = 0;
if(l == r && l == x) { cnt[k] += v, val[k] += x * v; return; }
if(x <= mid) update(ls[k], l, mid, x, v);
else update(rs[k], mid + 1, r, x, v);
cnt[k] = min(INF, cnt[ls[k]] + cnt[rs[k]]), val[k] = val[ls[k]] + val[rs[k]];
}
inline int query(int k, int l, int r, int x, int y){
if(!k) return 0;
if(l >= x && r <= y) return cnt[k];
if(y <= mid) return query(ls[k], l, mid, x, y);
else if(x > mid) return query(rs[k], mid + 1, r, x, y);
else return query(ls[k], l, mid, x, mid) + query(rs[k], mid + 1, r, mid + 1, y);
}
inline int ask(int k, int l, int r, int x, int y){
if(!k) return 0;
if(l >= x && r <= y) return val[k];
if(y <= mid) return ask(ls[k], l, mid, x, y);
else if(x > mid) return ask(rs[k], mid + 1, r, x, y);
else return ask(ls[k], l, mid, x, mid) + ask(rs[k], mid + 1, r, mid + 1, y);
}
}T;
signed main()
{
n = read();
for(re int i = 1; i <= n; i++)
a[i] = read(), b[i] = read(), T.update(rt, 0, lim, a[i], b[i]);
Q = read();
while(Q--){
int op = read(), x, y;
if(op == 1){
x = read(), y = read(), T.update(rt, 0, lim, a[x], -b[x]);
a[x] = y, T.update(rt, 0, lim, a[x], b[x]);
}
if(op == 2){
x = read(), y = read(), T.update(rt, 0, lim, a[x], -b[x]);
b[x] = y, T.update(rt, 0, lim, a[x], b[x]);
}
if(op == 3){
x = read();
if(T.cnt[rt] < x) { puts("-1"); continue; }
int l = 0, r = lim, res;
while(l <= r){
if(T.query(1, 0, lim, mid, lim) >= x) res = mid, l = mid + 1;
else r = mid - 1;
}
int all = T.query(1, 0, lim, res, lim);
int ans = T.ask(1, 0, lim, res, lim) - (all - x) * res;
printf("%lld\n", ans);
}
}
return 0;
}
/*
3
10 1
2 2
3 3
1
3 4
*/
Submission Info
Submission Time
2023-01-28 22:37:33+0900
Task
G - Balance Update Query
User
Booksnow
Language
C++ (GCC 9.2.1)
Score
600
Code Size
2681 Byte
Status
AC
Exec Time
909 ms
Memory
127116 KiB
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:54:14: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister]
54 | for(re int i = 1; i <= n; i++)
| ^
./Main.cpp:76:56: warning: ‘res’ may be used uninitialized in this function [-Wmaybe-uninitialized]
76 | int ans = T.ask(1, 0, lim, res, lim) - (all - x) * res;
| ~~~~~~~~~~^~~~~
Judge Result
Set Name
Sample
All
Score / Max Score
0 / 0
600 / 600
Status
Set Name
Test Cases
Sample
00_sample_00.txt
All
00_sample_00.txt, 01_rnd_00.txt, 01_rnd_01.txt, 01_rnd_02.txt, 01_rnd_03.txt, 02_rnd2_00.txt, 02_rnd2_01.txt, 02_rnd2_02.txt, 02_rnd2_03.txt, 03_samet_00.txt, 03_samet_01.txt, 03_samet_02.txt, 04_samea_00.txt, 04_samea_01.txt, 04_samea_02.txt, 04_samea_03.txt, 04_samea_04.txt, 04_samea_05.txt, 05_smallb_00.txt, 05_smallb_01.txt, 05_smallb_02.txt, 05_smallb_03.txt, 06_rotate_00.txt, 06_rotate_01.txt, 06_rotate_02.txt, 06_rotate_03.txt, 07_border_00.txt, 07_border_01.txt, 07_border_02.txt, 08_smallN_00.txt, 08_smallN_01.txt, 08_smallN_02.txt, 08_smallN_03.txt, 09_hand_00.txt, 09_hand_01.txt, 09_hand_02.txt, 09_hand_03.txt, 10_worst_00.txt, 10_worst_01.txt, 10_worst_02.txt
Case Name
Status
Exec Time
Memory
00_sample_00.txt
AC
7 ms
3624 KiB
01_rnd_00.txt
AC
275 ms
49172 KiB
01_rnd_01.txt
AC
413 ms
62500 KiB
01_rnd_02.txt
AC
75 ms
21508 KiB
01_rnd_03.txt
AC
404 ms
90220 KiB
02_rnd2_00.txt
AC
738 ms
109420 KiB
02_rnd2_01.txt
AC
440 ms
63900 KiB
02_rnd2_02.txt
AC
370 ms
59840 KiB
02_rnd2_03.txt
AC
498 ms
101044 KiB
03_samet_00.txt
AC
853 ms
90624 KiB
03_samet_01.txt
AC
838 ms
90500 KiB
03_samet_02.txt
AC
845 ms
90756 KiB
04_samea_00.txt
AC
157 ms
6884 KiB
04_samea_01.txt
AC
163 ms
6836 KiB
04_samea_02.txt
AC
182 ms
6824 KiB
04_samea_03.txt
AC
239 ms
6864 KiB
04_samea_04.txt
AC
277 ms
7540 KiB
04_samea_05.txt
AC
350 ms
12356 KiB
05_smallb_00.txt
AC
820 ms
115124 KiB
05_smallb_01.txt
AC
853 ms
115332 KiB
05_smallb_02.txt
AC
827 ms
115356 KiB
05_smallb_03.txt
AC
839 ms
114976 KiB
06_rotate_00.txt
AC
337 ms
28768 KiB
06_rotate_01.txt
AC
145 ms
31828 KiB
06_rotate_02.txt
AC
152 ms
31644 KiB
06_rotate_03.txt
AC
329 ms
28572 KiB
07_border_00.txt
AC
905 ms
127116 KiB
07_border_01.txt
AC
881 ms
127068 KiB
07_border_02.txt
AC
909 ms
127040 KiB
08_smallN_00.txt
AC
32 ms
11056 KiB
08_smallN_01.txt
AC
15 ms
6820 KiB
08_smallN_02.txt
AC
21 ms
7656 KiB
08_smallN_03.txt
AC
68 ms
18964 KiB
09_hand_00.txt
AC
114 ms
6796 KiB
09_hand_01.txt
AC
115 ms
6672 KiB
09_hand_02.txt
AC
281 ms
6692 KiB
09_hand_03.txt
AC
461 ms
115132 KiB
10_worst_00.txt
AC
82 ms
33492 KiB
10_worst_01.txt
AC
646 ms
33392 KiB
10_worst_02.txt
AC
369 ms
33456 KiB