QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#204530#7565. Harumachi Kazeucup-team1209#AC ✓2479ms52636kbC++203.8kb2023-10-07 12:57:042023-10-07 12:57:05

Judging History

你现在查看的是最新测评结果

  • [2023-10-07 12:57:05]
  • 评测
  • 测评结果:AC
  • 用时:2479ms
  • 内存:52636kb
  • [2023-10-07 12:57:04]
  • 提交

answer

#include<bits/stdc++.h>
using std::cin;
using std::cout;
using namespace std;
#define cs const
#define pb push_back
const int N = 100005;
const int mod = 963724301;
using ll = long long; 
using u64 = unsigned long long;
using pr = std::pair<u64, u64>;
u64 add(u64 x, u64 y) {
	if(x > y) std::swap(x, y);
	static std::map<pr, u64> map;
	pr a(x, y);
	if(map.count(a)) return map[a];
	cout << "A " << x << ' ' << y << std::endl;
	u64 res; cin >> res;
	return map[a] = res;
}
u64 cmp(u64 x, u64 y) {
	if(x > y) std::swap(x, y);
	static std::map<pr, u64> map;
	pr a(x, y);
	if(map.count(a)) return map[a];
	cout << "C " << x << ' ' << y << std::endl;
	u64 res; cin >> res;
	return map[a] = res;
}
int n, q, B;
struct sgt {
	u64 sum[N << 2];
	void build(int cur, int l, int r, u64 * a) {
		if(l == r) {
			sum[cur] = a[l];
			return ;
		}
		int mid = (l + r) >> 1;
		build(cur << 1, l, mid, a);
		build(cur << 1 | 1, mid + 1, r, a);
		sum[cur] = add(sum[cur << 1], sum[cur << 1 | 1]);
	}
	void upt(int cur, int pos, u64 v, int l = 1, int r = n) {
		if(l == r) {
			sum[cur] = v;
			return ;
		}
		int mid = (l + r) >> 1;
		if(pos <= mid) {
			upt(cur << 1, pos, v, l, mid);
		} else {
			upt(cur << 1 | 1, pos, v, mid + 1, r);
		}
		sum[cur] = add(sum[cur << 1], sum[cur << 1 | 1]);
	}
	void init(u64 * a) {
		build(1, 1, n, a);
	}
} s[2];
int op[N], t[N], pos[N], k[N];
u64 x[N];
u64 a[N], b[N];
struct node {
	sgt * s; int cur, l, r; u64 pre;
	int leaf() const {
		return l == r;
	}
	u64 lpre() const {
		return l == 1 ? s -> sum[cur << 1] : add(pre, s -> sum[cur << 1]);
	}
	u64 all() const {
		return l == 1 ? s -> sum[cur] : add(pre, s -> sum[cur]);
	}
	node ls() const {
		int mid = (l + r) >> 1;
		return {s, cur << 1, l, mid, pre};
	}
	node rs() const {
		int mid = (l + r) >> 1;
		return {s, cur << 1| 1, mid + 1, r, lpre()};
	}
	int lc() const {
		int mid = (l + r) >> 1;
		return mid - l + 1;
	}
};
u64 qry(node x, node y, int k) {
	if(x.leaf() && y.leaf()) {
		u64 xa = x.all();
		u64 ya = y.all();
		u64 min = cmp(xa, ya);
		if(k == 1) {
			return min;
		} else {
			return xa ^ ya ^ min;
		}
	}
	if(y.leaf()) std::swap(x, y);
	if(!x.leaf()) {
		u64 xa = x.lpre();
		u64 ya = y.lpre();
		u64 min = cmp(xa, ya);
		if(min != xa) {
			std::swap(xa, ya);
			std::swap(x, y);
		}
		if(x.lc() + y.lc() <= k) {
			return qry(x.rs(), y, k - x.lc());
		} else {
			return qry(x, y.ls(), k);
		}
	} else {
		u64 xa = x.all();
		u64 ya = y.lpre();
		int c = y.lc();
		c += cmp(xa, ya) == xa;
		if(k <= c) {
			return qry(x, y.ls(), k);
		} else {
			return qry(x, y.rs(), k - y.lc());
		}

	}
}
std::mt19937 gen;
int main() {
	cin >> n >> q >> B;
	for(int i = 1;i <= n;++i) {
		cin >> a[i];
	}
	for(int i = 1;i <= n;++i) {
		cin >> b[i];
	}
	for(int i = 1;i <= q;++i) {
		cin >> op[i];
		if(op[i] == 1) {
			cin >> t[i] >> pos[i] >> x[i];
		} else {
			cin >> k[i];
		}
	}
	/*
	for(int i = 1;i <= n;++i) {
		a[i] = gen() % 10;
	}
	for(int i = 1;i <= n;++i) {
		b[i] = gen() % 10;
	}
	for(int i = 1;i <= q;++i) {
		if(gen() & 1) {
			op[i] = 1;
			t[i] = gen() % 2 + 1;
			pos[i] = gen() % n + 1;
			x[i] = gen() % 10;
		} else {
			k[i] = gen() % (n + n) + 1;
		}
	}
	*/
	s[0].init(a);
	s[1].init(b);
	std::vector<u64> ans;
	for(int i = 1;i <= q;++i) {
		if(op[i] == 1) {
			s[t[i] - 1].upt(1, pos[i], x[i]);
			(t[i] == 1 ? a : b)[pos[i]] = x[i];
		} else {
			std::vector<u64> su;
			if(0) {
				u64 s = 0;
				for(int i = 1;i <= n;++i) su.push_back(s += a[i]);
				s = 0;
				for(int i = 1;i <= n;++i) su.push_back(s += b[i]);
				sort(su.begin(), su.end());
			}
			ans.push_back(qry({s, 1, 1, n, 0}, {s + 1, 1, 1, n, 0}, k[i]));
			// assert(ans.back() == su[k[i] - 1]);
		}
	}
	cout << "! " << ans.size() << '\n';
	for(u64 x : ans) cout << x << ' ';
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 9580kb

input:

2 3 2
288230376151711744 864691128455135232
1441151880758558720 2017612633061982208
2 3
1 2 2 2594073385365405696
2 3
1152921504606846976
3458764513820540928
288230376151711744
1152921504606846976
4035225266123964416

output:

A 288230376151711744 864691128455135232
A 1441151880758558720 2017612633061982208
C 288230376151711744 1441151880758558720
C 1152921504606846976 1441151880758558720
A 1441151880758558720 2594073385365405696
! 2
1441151880758558720 1441151880758558720 

result:

ok 2 lines

Test #2:

score: 0
Accepted
time: 1ms
memory: 9628kb

input:

3 5 3
2017612633061982208 864691128455135232 2305843009213693952
1441151880758558720 2017612633061982208 288230376151711744
2 5
2 2
1 1 3 1729382256910270464
1 2 1 2017612633061982208
2 5
2882303761517117440
5188146770730811392
3458764513820540928
3746994889972252672
2882303761517117440
345876451382...

output:

A 864691128455135232 2017612633061982208
A 2305843009213693952 2882303761517117440
A 1441151880758558720 2017612633061982208
A 288230376151711744 3458764513820540928
C 2882303761517117440 3458764513820540928
C 3458764513820540928 5188146770730811392
C 3746994889972252672 5188146770730811392
C 144115...

result:

ok 2 lines

Test #3:

score: 0
Accepted
time: 1748ms
memory: 44080kb

input:

16000 20000 14
12381691541923575949 2314459967875656919 15240288079556723088 320873566057825844 1013209648229540810 17538037439317817183 11476444495745028170 14967174865083701448 17232652930598276562 7175999203534983334 4597650078600036201 13978217693115848142 17682091621678261784 488328147143975490...

output:

A 2314459967875656919 12381691541923575949
A 320873566057825844 15240288079556723088
A 14696151509799232868 16557653430916204485
A 1013209648229540810 17538037439317817183
A 11476444495745028170 14967174865083701448
A 104503013837806377 7996875287119178002
A 9097870086258639932 12807060867005885737
...

result:

ok 2 lines

Test #4:

score: 0
Accepted
time: 1658ms
memory: 44244kb

input:

16000 20000 14
14874916021093924522 12369740409537030379 6287256359015658845 823444916947643237 4526221239260804705 11449122367236060745 5269387146536217002 12271448617436014402 2707995377102611522 953402166614134577 8882130735136249391 5659092195367212151 12689325453646244318 14372002311792512418 7...

output:

A 12369740409537030379 14874916021093924522
A 823444916947643237 6287256359015658845
A 7110701275963302082 9794404142223058838
A 4526221239260804705 11449122367236060745
A 5269387146536217002 12271448617436014402
A 90583475564335341 15975343606496865450
A 16905105418186360920 17062418867362856344
A ...

result:

ok 2 lines

Test #5:

score: 0
Accepted
time: 1892ms
memory: 43824kb

input:

16000 20000 14
12315377266285165767 11473010392351879640 7998004721169407057 9573065544888591349 8327463206443780344 16951550409690804427 9014132268830135915 1328673092737196637 5921820488166554289 3905417438586104204 16182336802010099310 4414669279483371512 13388655175283310101 4417487293134062765 ...

output:

A 11473010392351879640 12315377266285165767
A 7998004721169407057 9573065544888591349
A 6338135370229149344 17571070266057998406
A 8327463206443780344 16951550409690804427
A 1328673092737196637 9014132268830135915
A 6832269542425033155 10342805361567332552
A 6458953347879251687 18171566689294021260
...

result:

ok 2 lines

Test #6:

score: 0
Accepted
time: 1809ms
memory: 43300kb

input:

16000 20000 14
12381691541923575949 2314459967875656919 15240288079556723088 320873566057825844 1013209648229540810 17538037439317817183 11476444495745028170 14967174865083701448 17232652930598276562 7175999203534983334 4597650078600036201 13978217693115848142 17682091621678261784 488328147143975490...

output:

A 2314459967875656919 12381691541923575949
A 320873566057825844 15240288079556723088
A 14696151509799232868 16557653430916204485
A 1013209648229540810 17538037439317817183
A 11476444495745028170 14967174865083701448
A 104503013837806377 7996875287119178002
A 9097870086258639932 12807060867005885737
...

result:

ok 2 lines

Test #7:

score: 0
Accepted
time: 1888ms
memory: 44756kb

input:

16000 20000 14
14874916021093924522 12369740409537030379 6287256359015658845 823444916947643237 4526221239260804705 11449122367236060745 5269387146536217002 12271448617436014402 2707995377102611522 953402166614134577 8882130735136249391 5659092195367212151 12689325453646244318 14372002311792512418 7...

output:

A 12369740409537030379 14874916021093924522
A 823444916947643237 6287256359015658845
A 7110701275963302082 9794404142223058838
A 4526221239260804705 11449122367236060745
A 5269387146536217002 12271448617436014402
A 90583475564335341 15975343606496865450
A 16905105418186360920 17062418867362856344
A ...

result:

ok 2 lines

Test #8:

score: 0
Accepted
time: 1731ms
memory: 45384kb

input:

16000 20000 14
12315377266285165767 11473010392351879640 7998004721169407057 9573065544888591349 8327463206443780344 16951550409690804427 9014132268830135915 1328673092737196637 5921820488166554289 3905417438586104204 16182336802010099310 4414669279483371512 13388655175283310101 4417487293134062765 ...

output:

A 11473010392351879640 12315377266285165767
A 7998004721169407057 9573065544888591349
A 6338135370229149344 17571070266057998406
A 8327463206443780344 16951550409690804427
A 1328673092737196637 9014132268830135915
A 6832269542425033155 10342805361567332552
A 6458953347879251687 18171566689294021260
...

result:

ok 2 lines

Test #9:

score: 0
Accepted
time: 2065ms
memory: 50904kb

input:

16000 20000 14
12381691541923575949 2314459967875656919 15240288079556723088 320873566057825844 1013209648229540810 17538037439317817183 11476444495745028170 14967174865083701448 17232652930598276562 7175999203534983334 4597650078600036201 13978217693115848142 17682091621678261784 488328147143975490...

output:

A 2314459967875656919 12381691541923575949
A 320873566057825844 15240288079556723088
A 14696151509799232868 16557653430916204485
A 1013209648229540810 17538037439317817183
A 11476444495745028170 14967174865083701448
A 104503013837806377 7996875287119178002
A 9097870086258639932 12807060867005885737
...

result:

ok 2 lines

Test #10:

score: 0
Accepted
time: 2372ms
memory: 52636kb

input:

16000 20000 14
14874916021093924522 12369740409537030379 6287256359015658845 823444916947643237 4526221239260804705 11449122367236060745 5269387146536217002 12271448617436014402 2707995377102611522 953402166614134577 8882130735136249391 5659092195367212151 12689325453646244318 14372002311792512418 7...

output:

A 12369740409537030379 14874916021093924522
A 823444916947643237 6287256359015658845
A 7110701275963302082 9794404142223058838
A 4526221239260804705 11449122367236060745
A 5269387146536217002 12271448617436014402
A 90583475564335341 15975343606496865450
A 16905105418186360920 17062418867362856344
A ...

result:

ok 2 lines

Test #11:

score: 0
Accepted
time: 2479ms
memory: 50752kb

input:

16000 20000 14
12315377266285165767 11473010392351879640 7998004721169407057 9573065544888591349 8327463206443780344 16951550409690804427 9014132268830135915 1328673092737196637 5921820488166554289 3905417438586104204 16182336802010099310 4414669279483371512 13388655175283310101 4417487293134062765 ...

output:

A 11473010392351879640 12315377266285165767
A 7998004721169407057 9573065544888591349
A 6338135370229149344 17571070266057998406
A 8327463206443780344 16951550409690804427
A 1328673092737196637 9014132268830135915
A 6832269542425033155 10342805361567332552
A 6458953347879251687 18171566689294021260
...

result:

ok 2 lines