UOJ Logo

NOI.AC

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#194715#2038. btkswls1003251ms33700kbC++111.6kb2023-10-17 09:41:192023-10-17 12:03:39

answer

#include <bits/stdc++.h>
using namespace std;
int cnt,  m, ls[2000006], lss[2000006], ct, ctt, l[1000006];
struct node {
	int op, p;
} b[1000006];
inline int finds(int p) {
	return lower_bound(ls + 1, ls + ct + 1, p) - ls;
}
inline int findss(int p) {
	return lower_bound(lss + 1, lss + ctt + 1, p) - lss;
}
inline int lowbit(int p) {
	return p & -p;
}
struct SGT {
	int t[2000006], n;
	inline void add(int p, int q) {
//		cout << p << "||" << q << "||" << n << endl;
		while (p <= n) {
			t[p] += q;
			p += lowbit(p);
		}
	}
	inline int query(int p) {
		int ans = 0;
		while (p >= 1) {
			ans += t[p];
			p -= lowbit(p);
		}
		return ans;
	}
} p, q;
signed main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin  >> m;
	for (int i = 1; i <= m; i++) {
		cin >> b[i].op >> b[i].p;
		if (b[i].op == 0) {
			lss[++cnt] = b[i].p + cnt;
			ls[2 * cnt - 1] = b[i].p;
			ls[2 * cnt] = b[i].p + 1;
		}
	}
	sort(ls + 1, ls + 2 * cnt + 1);
	sort(lss + 1, lss + cnt + 1);
	ls[0] = lss[0] = -1;
	for (int i = 1; i <= 2 * cnt; i++) {
		if (ls[i] != ls[i - 1]) {
			ls[++ct] = ls[i];
		}
	}
	for (int i = 1; i <= cnt; i++) {
		if (lss[i] != lss[i - 1]) {
			lss[++ctt] = lss[i];
		}
	}
	p.n = ct, q.n = ctt;
	cnt = 0;
	for (int i = 1; i <= m; i++) {
		if (b[i].op == 0) {
			cout << p.query(finds(b[i].p)) + q.query(findss(cnt + 1 + b[i].p)) << "\n";
			l[++cnt] = b[i].p;
			p.add(finds(b[i].p + 1), -1);
			q.add(findss(b[i].p + cnt), 1);
		} else {
			p.add(finds(l[b[i].p] + 1), 1);
			q.add(findss(b[i].p + l[b[i].p]), -1);
		}
	}
}

Details

小提示:点击横条可展开更详细的信息

Test #1:

score: 10
Accepted
time: 0ms
memory: 1308kb

input:

666
0 -389
0 -952
0 143
1 1
0 6
0 179
0 -923
0 -20
0 302
0 -109
1 8
0 894
0 -573
0 494
0 -385
0 -873...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
1
0
0
0
0
0
0
1
1
0
0
0
0
0
0
0
1
1
0
2
0
0
0
0
1
0
0
...

result:

ok 593 numbers

Test #2:

score: 10
Accepted
time: 0ms
memory: 1320kb

input:

1000
0 588
1 1
0 -628
0 -956
0 -665
0 765
0 -190
0 -576
0 -813
0 -292
0 274
1 10
0 651
0 -205
0 -574...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
1
0
0
0
0
0
0
0
1
0
0
0
1
0
0
0
1
...

result:

ok 888 numbers

Test #3:

score: 10
Accepted
time: 35ms
memory: 2576kb

input:

50000
0 -7094
0 -8664
0 -9115
1 3
0 -9755
0 -3119
0 4344
0 1734
1 5
0 -3462
1 7
0 7843
0 5728
0 -562...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
...

result:

ok 44900 numbers

Test #4:

score: 10
Accepted
time: 52ms
memory: 3072kb

input:

70000
0 -5155
1 1
0 9088
0 6886
0 -5081
0 1938
0 -959
0 -8158
0 414
1 4
0 6503
0 2048
0 9571
0 -9902...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 63042 numbers

Test #5:

score: 10
Accepted
time: 63ms
memory: 3428kb

input:

85000
0 -8442
0 7059
0 2716
0 307
1 1
0 1173
0 -2796
1 2
0 -3617
0 5458
0 -1083
0 -3482
1 5
0 2832
0...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 76519 numbers

Test #6:

score: 10
Accepted
time: 79ms
memory: 3788kb

input:

100000
0 -3400
0 -3786
0 -4616
0 -3125
0 -3813
0 9233
1 1
0 32
0 -5027
0 -6531
0 -9932
0 -8502
0 -31...

output:

0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 90009 numbers

Test #7:

score: 10
Accepted
time: 308ms
memory: 11020kb

input:

300000
0 -578222155
1 1
0 -464946128
0 -503954765
0 -579608591
0 -147391629
1 2
0 -140936373
1 4
0 -...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 270045 numbers

Test #8:

score: 10
Accepted
time: 564ms
memory: 17512kb

input:

500000
0 -879047197
0 22865740
0 -579471564
0 -455491333
0 -632783600
0 -345134153
0 -341714454
0 -7...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 450086 numbers

Test #9:

score: 10
Accepted
time: 854ms
memory: 23980kb

input:

700000
0 -106097647
0 -135803415
0 -694029768
0 -407027902
1 2
1 3
0 -534078466
0 -317401273
0 -2520...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 629728 numbers

Test #10:

score: 10
Accepted
time: 1296ms
memory: 33700kb

input:

1000000
0 -759131017
0 -632412881
0 -712627012
0 -353714850
0 -207626084
0 -545766331
0 -423546500
0...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 899925 numbers

Extra Test:

score: 0
Extra Test Passed