QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#88569#5669. Traveling in Jade Cityblack_iceWA 447ms34536kbC++142.5kb2023-03-16 15:41:272023-03-16 15:41:29

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-16 15:41:29]
  • 评测
  • 测评结果:WA
  • 用时:447ms
  • 内存:34536kb
  • [2023-03-16 15:41:27]
  • 提交

answer

#include <iostream>
#include <algorithm>
#include <math.h>
#include <unordered_map>
#include <queue>
#include <vector>
#include <cstring>
using namespace std;
typedef long long ll;
#define x first
#define y second
#define int long long
#define endl '\n'
typedef pair<int,int> PII;
const int N = 2e6 + 10,mod = 998244353,M = 2 * N,INF = 1e9;
int c[N],x[N],tr[N * 2];
int T,n,k,m,q;

int lowbit(int x){
	return x & -x;
}

void modify(int x,int c){
	for(int i = x;i <= n + m;i += lowbit(i)) tr[i] += c;
}

int query(int x){
	int res = 0;
	for(int i = x;i;i -= lowbit(i)) res += tr[i];
	return res;
}

void solve()
{
	cin >> n >> k >> m >> q;
	m++;
	for(int i = 1;i <= n;i++) cin >> c[i],modify(i,c[i]);
	for(int i = 1;i <= m;i++) cin >> x[i],modify(n + i,x[i]);
	while(q--)
	{
		char op[2];
		cin >> op;
		if(*op == 'q'){
			int u,v;
			cin >> u >> v;
			if(u > v) swap(u,v);
			int tmp1,tmp2,tmp3;
			if(v <= n){
				tmp1 = query(v - 1) - query(u - 1);
				tmp2 = query(n) - tmp1;
				tmp3 = 0;
				if(u <= k && v <= k){
					tmp3 = query(n + m) - query(n) + query(u - 1) + query(k - 1) - query(v - 1);
				}
				else if(v > k && u <= k){
					tmp3 = query(n + m) - query(n) + query(u - 1) + query(v - 1) - query(k - 1);
					tmp3 = min(tmp3,query(n + m) - query(v - 1) + query(k - 1) - query(u - 1));
				}
				else{
					tmp3 = query(n + m) - query(v - 1) + query(u - 1) - query(k - 1);
				}
			}
			else if(u <= n && v > n){
				if(u <= k){
					tmp1 = query(n + m) - query(v) + query(k - 1) - query(u - 1);
					tmp2 = query(v) - query(n) + query(u - 1);
					tmp3 = query(v) - query(u - 1);
				}
				else{
					tmp1 = query(v) - query(u - 1);
					tmp2 = query(n + m) - query(v) + query(u - 1) - query(k - 1);
					tmp3 = query(u - 1) + query(v) - query(n);
				}
			}
			else{
				tmp1 = query(v) - query(u);
				tmp2 = query(n + m) - query(v) + query(u) - query(k - 1);
				tmp3 = query(n + m) - query(v) + query(u) - query(n) + query(k - 1);
			}
			int ans = min(tmp1,min(tmp2,tmp3));
			if(ans >= INF) cout << "impossible" << endl;
			else cout << ans << endl;
		}
		else if(*op == 'c'){
			int num;
			cin >> num;
			if(c[num] >= INF) modify(num,-INF),c[num] -= INF;
			else modify(num,INF),c[num] += INF;
		}
		else{
			int num;
			cin >> num;
			num++;
			if(x[num] >= INF) modify(num + n,-INF),x[num] -= INF;
			else modify(num + n,INF),x[num] += INF;
		}
	}
}

signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	T = 1;
	while(T--)
	{
		solve();
	}	
}  

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

4 3 1 9
2 3 8 4
1 1
q 3 4
x 0
q 3 4
c 3
q 3 4
c 1
q 3 4
x 0
q 3 4

output:

6
8
9
impossible
6

result:

ok 5 lines

Test #2:

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

input:

4 3 1 9
2 3 8 4
1 1
q 3 4
x 0
q 3 4
c 3
q 3 4
c 1
q 3 4
x 0
q 3 4

output:

6
8
9
impossible
6

result:

ok 5 lines

Test #3:

score: -100
Wrong Answer
time: 447ms
memory: 34536kb

input:

1000000 999999 1000000 1000000
200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 2...

output:

177406400
122264600
181690600
impossible
impossible
impossible
impossible
impossible
impossible
impossible
impossible
impossible
29295200
impossible
22163200
impossible
impossible
impossible
11422200
impossible
62579800
impossible
35339400
impossible
20157200
impossible
impossible
impossible
impossi...

result:

wrong answer 3rd lines differ - expected: '70328400', found: '181690600'