QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#205563#7565. Harumachi Kazeucup-team1453#AC ✓1654ms75420kbC++143.6kb2023-10-07 16:33:262023-10-07 16:33:27

Judging History

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

  • [2023-10-07 16:33:27]
  • 评测
  • 测评结果:AC
  • 用时:1654ms
  • 内存:75420kb
  • [2023-10-07 16:33:26]
  • 提交

answer

#include<bits/stdc++.h>
#define L(i, j, k) for(int i = (j); i <= (k); ++i)
#define R(i, j, k) for(int i = (j); i >= (k); --i)
#define ll long long 
#define vi vector < int > 
#define sz(a) ((int) (a).size())
#define ll long long 
#define ull unsigned long long
#define me(a, x) memset(a, x, sizeof(a)) 
using namespace std;
const int N = 1e5 + 7;

struct Data {
	ull x;
	Data (ull X = 0) {
		x = X;
	}
};

map < pair < ull, ull >, Data > Add;
map < pair < ull, ull >, bool > Cmp;
Data operator + (Data u, Data v) {
	if(u.x == 0 || v.x == 0) return Data(u.x + v.x); 
	if(Add.count(make_pair(u.x, v.x))) return Add[make_pair(u.x, v.x)];
//	return Data(u.x + v.x); // delete
	cout << "A " << u.x << ' ' << v.x << endl;
	
	ull w;
	cin >> w;
	return Add[make_pair(u.x, v.x)] = Data(w);
}

bool operator < (Data u, Data v) {
	if(u.x == v.x) return false;
	if(Cmp.count(make_pair(u.x, v.x))) return Cmp[make_pair(u.x, v.x)];
//	return u.x < v.x; // delete
	
	cout << "C " << u.x << ' ' << v.x << endl;
	ull w;
	cin >> w;
	return Cmp[make_pair(u.x, v.x)] = w == u.x;
}

int n, q, B;
int type[N], qk[N], qt[N], qpos[N];
ull qx[N];

struct ds {
	Data cm[20][N];
	void build(ull *a) {
		L(i, 0, n - 1) {
			cm[0][i] = Data(a[i]);
		}
		L(h, 1, 19) {
			for(int i = 0; i < n; i += 1 << h) {
				if(i + (1 << h) - 1 >= n) {
					continue;
				}
				cm[h][i] = cm[h - 1][i] + cm[h - 1][i + (1 << (h - 1))];
			}
		}
	}
	void modify(int p, ull w) {
		cm[0][p] = Data(w);
		L(h, 1, 19) {
			int i = (p >> h) << h;
			if((i + (1 << h) - 1) >= n) {
				continue;
			}
			cm[h][i] = cm[h - 1][i] + cm[h - 1][i + (1 << (h - 1))];
		}
	}
} ds1, ds2;

ull va[N], vb[N];
int main() {
	ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n >> q >> B;
	L(i, 0, n - 1) {
		cin >> va[i];
	}
	L(i, 0, n - 1) {
		cin >> vb[i];
	}
	L(t, 1, q) {
		cin >> type[t];
		if(type[t] == 1) {
			cin >> qt[t] >> qpos[t] >> qx[t], --qpos[t];
		} else {
			cin >> qk[t];
		}
	}
	ds1.build(va);
	ds2.build(vb);
	
	vector < ull > ans;
	L(t, 1, q) {
		if(type[t] == 1) {
			if(qt[t] == 1) {
				ds1.modify(qpos[t], qx[t]);
				va[qpos[t]] = qx[t];
			} else {
				ds2.modify(qpos[t], qx[t]);
				vb[qpos[t]] = qx[t];
			}
		} else if(type[t] == 2) {
			int k = qk[t];
			
//			cout << "values : " << endl;
//			L(i, 0, n - 1) {
//				cout << va[i] << ' ';
//			}
//			cout << endl;
//			L(i, 0, n - 1) {
//				cout << vb[i] << ' ';
//			}
//			cout << endl;
//			cout << "query : k = " << k << endl;
			int pos[2] = {0, 0};
			Data sum[2] = {0, 0};
			
			int curh = 20;
			while(k > 1) {
				while((1 << (curh + 1)) > k)
					--curh;
				if(pos[0] + (1 << curh) - 1 >= n) {
					sum[1] = sum[1] + ds2.cm[curh][pos[1]];
					pos[1] += 1 << curh;
				} else if(pos[1] + (1 << curh) - 1 >= n) {
					sum[0] = sum[0] + ds1.cm[curh][pos[0]];
					pos[0] += 1 << curh;
				} else {
					if(sum[0] + ds1.cm[curh][pos[0]] < sum[1] + ds2.cm[curh][pos[1]]) {
						sum[0] = sum[0] + ds1.cm[curh][pos[0]];
						pos[0] += 1 << curh;
					} else {
						sum[1] = sum[1] + ds2.cm[curh][pos[1]];
						pos[1] += 1 << curh;
					}
				}
				k -= 1 << curh;
			}
			if(pos[0] == n) 
				ans.emplace_back((sum[1] + ds2.cm[0][pos[1]]).x);
			else if(pos[1] == n) 
				ans.emplace_back((sum[0] + ds1.cm[0][pos[0]]).x);
			else 
				ans.emplace_back(
					min(sum[0] + ds1.cm[0][pos[0]], sum[1] + ds2.cm[0][pos[1]]).x); 
		}
	} 
	
	cout << "! " << sz(ans) << endl;
	for(auto&u : ans) cout << u << ' ';
	cout << endl;
	return 0;
}

/*
2 3 2
1 3
5 7
2 3
1 2 2 9
2 1

*/ 

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 36656kb

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: 0ms
memory: 36376kb

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
3458764513820540928
2882303761517117440
5188146770730811392
1441151880758558720
345876451382...

output:

A 2017612633061982208 864691128455135232
A 1441151880758558720 2017612633061982208
C 2882303761517117440 3458764513820540928
A 2882303761517117440 2305843009213693952
C 5188146770730811392 1441151880758558720
C 5188146770730811392 3458764513820540928
A 3458764513820540928 288230376151711744
C 374699...

result:

ok 2 lines

Test #3:

score: 0
Accepted
time: 1378ms
memory: 68864kb

input:

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

output:

A 12381691541923575949 2314459967875656919
A 15240288079556723088 320873566057825844
A 1013209648229540810 17538037439317817183
A 11476444495745028170 14967174865083701448
A 17232652930598276562 7175999203534983334
A 4597650078600036201 13978217693115848142
A 17682091621678261784 4883281471439754902...

result:

ok 2 lines

Test #4:

score: 0
Accepted
time: 1508ms
memory: 69412kb

input:

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

output:

A 14874916021093924522 12369740409537030379
A 6287256359015658845 823444916947643237
A 4526221239260804705 11449122367236060745
A 5269387146536217002 12271448617436014402
A 2707995377102611522 953402166614134577
A 8882130735136249391 5659092195367212151
A 12689325453646244318 14372002311792512418
A ...

result:

ok 2 lines

Test #5:

score: 0
Accepted
time: 1523ms
memory: 68792kb

input:

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

output:

A 12315377266285165767 11473010392351879640
A 7998004721169407057 9573065544888591349
A 8327463206443780344 16951550409690804427
A 9014132268830135915 1328673092737196637
A 5921820488166554289 3905417438586104204
A 16182336802010099310 4414669279483371512
A 13388655175283310101 4417487293134062765
A...

result:

ok 2 lines

Test #6:

score: 0
Accepted
time: 1345ms
memory: 68276kb

input:

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

output:

A 12381691541923575949 2314459967875656919
A 15240288079556723088 320873566057825844
A 1013209648229540810 17538037439317817183
A 11476444495745028170 14967174865083701448
A 17232652930598276562 7175999203534983334
A 4597650078600036201 13978217693115848142
A 17682091621678261784 4883281471439754902...

result:

ok 2 lines

Test #7:

score: 0
Accepted
time: 1346ms
memory: 69424kb

input:

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

output:

A 14874916021093924522 12369740409537030379
A 6287256359015658845 823444916947643237
A 4526221239260804705 11449122367236060745
A 5269387146536217002 12271448617436014402
A 2707995377102611522 953402166614134577
A 8882130735136249391 5659092195367212151
A 12689325453646244318 14372002311792512418
A ...

result:

ok 2 lines

Test #8:

score: 0
Accepted
time: 1338ms
memory: 68112kb

input:

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

output:

A 12315377266285165767 11473010392351879640
A 7998004721169407057 9573065544888591349
A 8327463206443780344 16951550409690804427
A 9014132268830135915 1328673092737196637
A 5921820488166554289 3905417438586104204
A 16182336802010099310 4414669279483371512
A 13388655175283310101 4417487293134062765
A...

result:

ok 2 lines

Test #9:

score: 0
Accepted
time: 1594ms
memory: 75420kb

input:

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

output:

A 12381691541923575949 2314459967875656919
A 15240288079556723088 320873566057825844
A 1013209648229540810 17538037439317817183
A 11476444495745028170 14967174865083701448
A 17232652930598276562 7175999203534983334
A 4597650078600036201 13978217693115848142
A 17682091621678261784 4883281471439754902...

result:

ok 2 lines

Test #10:

score: 0
Accepted
time: 1555ms
memory: 74808kb

input:

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

output:

A 14874916021093924522 12369740409537030379
A 6287256359015658845 823444916947643237
A 4526221239260804705 11449122367236060745
A 5269387146536217002 12271448617436014402
A 2707995377102611522 953402166614134577
A 8882130735136249391 5659092195367212151
A 12689325453646244318 14372002311792512418
A ...

result:

ok 2 lines

Test #11:

score: 0
Accepted
time: 1654ms
memory: 75224kb

input:

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

output:

A 12315377266285165767 11473010392351879640
A 7998004721169407057 9573065544888591349
A 8327463206443780344 16951550409690804427
A 9014132268830135915 1328673092737196637
A 5921820488166554289 3905417438586104204
A 16182336802010099310 4414669279483371512
A 13388655175283310101 4417487293134062765
A...

result:

ok 2 lines