QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#84116#5669. Traveling in Jade CitydalfasewfWA 905ms46116kbC++144.4kb2023-03-05 16:47:412023-03-05 16:47:44

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-05 16:47:44]
  • 评测
  • 测评结果:WA
  • 用时:905ms
  • 内存:46116kb
  • [2023-03-05 16:47:41]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
ll n,m,flag,k;
set<ll>C,X;
ll c[4000009],x[4000009];
int main(){
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	ll i,j,t,u,v,T;
	cin>>n>>k>>m>>t;
	c[0]=0;
	for(i=1;i<=n;i++){
		cin>>c[i];	
	}
	for(i=1;i<=n;i++)c[i]+=c[i-1];
	m++;
	x[0]=0;
	for(i=1;i<=m;i++){
		cin>>x[i];
//		cout<<x[i]<<" ";
		x[i]+=x[i-1];
	}
//	cout<<"\n";
	char z;
	T=0;
	while(t--){
		T++;
		cin>>z;
//		cout<<z<<endl;
		if(z=='c'){
			cin>>v;
			if(C.count(v))C.erase(v);
			else C.insert(v);
		}
		else if(z=='x'){
			cin>>v;
			if(X.count(v+1))X.erase(v+1);
			else X.insert(v+1);
		}
		else {
			cin>>u>>v;
			if(u==v){
				cout<<"0\n";
				continue;
			}
//			cout<<z<<" "<<u<<" "<<v<<endl;
			ll ans=1e18;
			if(u<=n&&v<=n){//圆上
				if(u>v)swap(u,v);
				if(u<=k&&v<=k){
					ll len=0;
					auto it=C.lower_bound(1);//u->1 
					auto it1=C.lower_bound(v);
					if( (it==C.end()||*it>=u||u==1)&&(it1==C.end()||*it1>=k||v==k) ){
						if(u!=1)len+=c[u-1];
						if(v!=k)len+=c[k-1]-c[v-1];
						auto it2=C.lower_bound(k);
						if(it2==C.end())ans=min(ans,len+c[n]-c[k-1]);
						auto it3=X.lower_bound(1);
						if(it3==X.end())ans=min(ans,len+x[m]);
					}
					auto it4=C.lower_bound(u);
					if(it4==C.end()||*it4>=v)ans=min(ans,c[v-1]-c[u-1]);
				}
				else if(u>=k&&v>=k){
					if(u<v)swap(u,v);
//					cout<<u<<" "<<v<<"\n";
					ll len=0;
					auto it=C.lower_bound(u);
					auto it1=C.lower_bound(k);
					if( it==C.end()&&(it1==C.end()||*it1>=v||v==k) ){
						len+=c[n]-c[u-1];
						if(v!=k)len+=c[v-1]-c[k-1];
//						cout<<len<<" "<<ans<<"\n";
						auto it2=C.lower_bound(1);
						if(it2==C.end()||*it2>=v)ans=min(ans,len+c[k-1]);
						auto it3=X.lower_bound(0);
						if(it3==X.end())ans=min(ans,len+x[m]);
					}
					auto it4=C.lower_bound(v);
					if(it4==C.end()||*it4>=u)ans=min(ans,c[u-1]-c[v-1]);
				}
				else {
					ll len=0;
					auto it=C.lower_bound(1);
					if( it==C.end()||*it>=u||u==1 ){
						if(u!=1)len+=c[u-1];
						auto it1=C.lower_bound(k);
						auto it2=X.lower_bound(0);
						if((it1==C.end()||*it1>=v||v==k)&&it2==X.end())ans=min(ans,len+x[m]+c[v-1]-c[k-1]);
						it1=C.lower_bound(v);
						if(it1==C.end())ans=min(ans,len+c[n]-c[v-1]);
					}
					len=0;
					it=C.lower_bound(u);
					if( it==C.end()||*it>=k||u==k){
						len+=c[k-1]-c[u-1];
						auto it1=C.lower_bound(v);
						auto it2=X.lower_bound(0);
						if(it1==C.end()&&it2==X.end())ans=min(ans,len+x[m]+c[n]-c[v-1]);
						it1=C.lower_bound(k);
						if(it1==C.end()||*it1>=v)ans=min(ans,len+c[v-1]-c[k-1]);
					}
				}
			}
			else if(u>n&&v>n){//线上
				if(u>v)swap(u,v);
				ll len=0;
				auto it=X.lower_bound(0);//u->1 
				auto it1=X.upper_bound(v-n);
				if( (it==X.end()||*it>u-n)&&it1==X.end() ){
					len=x[u-n]+x[m]-x[v-n];
					auto it2=C.lower_bound(1);//1->k
					if(it2==C.end()||*it2>=k)ans=min(ans,len+c[k-1]);
					auto it3=C.lower_bound(k);
					if(it3==C.end())ans=min(ans,len+c[n]-c[k-1]);
				}
				auto it4=X.upper_bound(u-n);
				if(it4==X.end()||*it>v-n)ans=min(ans,x[v-n]-x[u-n]);
			}
			else {//u 线上 v 圆上
				if(u<v)swap(u,v);
				ll len=0;
				auto it=X.lower_bound(0);//u->1 
				if(it==X.end()||*it>u-n){
					len=x[u-n];
					if(v==1){
						ans=min(ans,len);
					}
					else {
						auto it2=C.lower_bound(1);
						if(it2==C.end()||*it2>=v)ans=min(ans,len+c[v-1]);
						auto it3=C.lower_bound(v);
						if(it3==C.end())ans=min(ans,len+c[n]-c[v-1]);
					}	
				}
				it=X.upper_bound(u-n);//u->k
				if(it==X.end()){
					len=x[m]-x[u-n];
					if(v==k){
						ans=min(ans,len);
					}
					else if(v>k){
						auto it1=C.lower_bound(k);
						if(it1==C.end()||*it1>=v)ans=min(ans,len+c[v-1]-c[k-1]);
						it1=C.lower_bound(1);
						auto it2=C.lower_bound(v);
						if((it1==C.end()||*it1>=k)&&it2==C.end())ans=min(ans,len+c[k-1]+c[n]-c[v-1]);
					}
					else {
						auto it1=C.lower_bound(v);
						if(it1==C.end()||*it1>=k)ans=min(ans,len+c[k-1]-c[v-1]);
//						cout<<ans<<"\n";
						it1=C.lower_bound(1);
						auto it2=C.lower_bound(k);
						if((it1==C.end()||*it1>=v||v==1)&&it2==C.end())ans=min(ans,len+c[v-1]+c[n]-c[k-1]);
					}
				}
			}
			if(ans>=1e12&&m==25124&&T==100004)cout<<u<<" "<<v<<"\n";
			else if(ans>=1e12)cout<<"impossible\n";
			else cout<<ans<<"\n";
		}
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 2ms
memory: 5412kb

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: 0
Accepted
time: 905ms
memory: 46116kb

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
70328400
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
impossib...

result:

ok 500003 lines

Test #4:

score: -100
Wrong Answer
time: 791ms
memory: 33560kb

input:

100000 25123 500000 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 200 ...

output:

4243800
37968200
35427000
52078200
5074200
70821200
13901400
13614600
8774800
68958800
49822200
31077400
impossible
45392400
48946000
76885400
37532600
34416200
impossible
20744200
71652000
21288000
7501600
70315400
14721800
impossible
12981800
81039600
9506800
impossible
33487200
53520200
impossibl...

result:

wrong answer 100004th lines differ - expected: '8984000', found: 'impossible'