QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#524216 | #5669. Traveling in Jade City | ucup-team3699# | WA | 536ms | 58384kb | C++20 | 5.0kb | 2024-08-19 12:45:36 | 2024-08-19 12:45:36 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define F first
#define S second
const int mol=998244353;
const int N = 1e6+5;
int c[N], x[N];
set<int>n1, n2;
int pre1[1000005], pre2[1000005];
int n, k, m, q;
bool no(int t1, int t2){
if(t2==-1){
if(*n1.lower_bound(t1)>=n+1) return 1;
return 0;
}
if(t1>t2) swap(t1, t2);
if(t2<=n){
if(*n1.lower_bound(t1)>=t2) return 1;
return 0;
}
else{
if(t1==1) t1=0;
else t1-=n;
t2-=n;
if(*n2.lower_bound(t1)>=t2) return 1;
return 0;
}
}
void solve(){
cin>>n>>k>>m>>q;
for(int i=1;i<=n;i++) cin>>c[i], pre1[i]=pre1[i-1]+c[i];
for(int i=0;i<=m;i++) {
cin>>x[i];
if(i==0) pre2[i]=x[i];
else pre2[i]=pre2[i-1]+x[i];
}
n1.insert(1e18), n2.insert(1e18);
while(q--){
char t;
cin>>t;
if(t=='q'){
int g, h;
cin>>g>>h;
if(g==h){
cout<<"0\n";
continue;
}
if(g>h) swap(g, h);
int ans=1e18;
if(h<=k){
if(*n1.lower_bound(g)>=h) ans=pre1[h-1]-pre1[g-1];
if(no(1, g)&&no(1, n+m+1)&&no(h, k)) ans=min(ans, pre1[g-1]+pre2[m]+pre1[k-1]-pre1[h-1]);
if(no(1, g)&&no(h, -1)) ans=min(ans, pre1[n]-pre1[h-1]+pre1[g-1]);
}
else if(h<=n){
if(g<k){
if(no(g, h)) ans=pre1[h-1]-pre1[g-1];
if(no(1, g)&&no(h, -1)) ans=min(ans, pre1[g-1]+pre1[n]-pre1[h-1]);
if(n2.size()==0){
if(no(g, k)&&no(h, -1)) ans=min(ans, pre2[m]+pre1[k-1]-pre1[g-1]+pre1[n]-pre1[h-1]);
if(no(1, g)&&no(k, h)) ans=min(ans, pre2[m]+pre1[g-1]+pre1[h-1]-pre1[k-1]);
}
}
else{
if(no(g, h)) ans=pre1[h-1]-pre1[g-1];
if(no(h, -1)&&no(k, g)&&no(1, n+m+1)) ans=min(ans, pre1[g-1]-pre1[k-1]+pre2[m]+pre1[n]-pre1[h-1]);
// cout<<no(1, g)<<" "<<no(h, -1)<<"haha\n";
if(no(1, g)&&no(h, -1)) ans=min(ans, pre1[n]-pre1[h-1]+pre1[g-1]);
}
}
else{
if(g==1){
if(no(1, h)) ans=min(ans, pre2[h-1]);
if(no(1, k)&&no(h, n+m+1)) ans=min(ans, pre1[k-1]+pre2[m]-pre2[h-n-1]);
if(no(k, -1)&&no(h, n+m+1)) ans=min(ans, pre1[n]-pre1[k-1]+pre2[m]-pre2[h-n-1]);
}
else if(g==k){
if(no(h, n+m+1)) ans=min(ans, pre2[m]-pre2[h-1]);
if(no(1, k)&&no(1, h)) ans=min(ans, pre1[k-1]+pre2[h-n-1]);
if(no(k, -1)&&no(1, h)) ans=min(ans, pre1[n]-pre1[k-1]+pre2[h-n-1]);
}
else if(g>=n+1){
if(no(g, h)) ans=pre2[h-n-1]-pre2[g-n-1];
if(no(1, g)&&no(h, n+m+1)){
if(no(k, -1)) ans=min(ans, pre2[g-n-1]+pre2[m]-pre2[h-n-1]+pre1[n]-pre1[k-1]);
if(no(1, k)) ans=min(ans, pre2[g-n-1]+pre2[m]-pre2[h-n-1]+pre1[k-1]);
}
}
else{
if(g<=k-1){
if(no(h, n+m+1)){
if(no(g, k)) ans=min(ans, pre1[k-1]-pre1[g-1]+pre2[m]-pre2[h-n-1]);
if(no(1, g)&&no(k, -1)) ans=min(ans, pre1[g-1]+pre1[n]-pre1[k-1]+pre2[m]-pre2[h-n-1]);
}
if(no(1, h)){
if(no(1, g)) ans=min(ans, pre1[g-1]+pre2[h-n-1]);
if(no(g, -1)) ans=min(ans, pre1[n]-pre1[g-1]+pre2[h-n-1]);
}
}
else{
if(no(h, n+m+1)){
if(no(k, g)) ans=min(ans, pre1[g-1]-pre1[k-1]+pre2[m]-pre2[h-n-1]);
if(no(g, -1)&&no(1, k)) ans=min(ans, pre1[k-1]+pre1[n]-pre1[g-1]+pre2[m]-pre2[h-n-1]);
}
if(no(1, h)){
if(no(1, g)) ans=min(ans, pre1[g-1]+pre2[h-n-1]);
if(no(g, -1)) ans=min(ans, pre1[n]-pre1[g-1]+pre2[h-n-1]);
}
}
}
}
if(ans==1e18) cout<<"impossible\n";
else cout<<ans<<"\n";
}
if(t=='c'){
int g;
cin>>g;
if(n1.count(g)) n1.erase(g);
else n1.insert(g);
}
if(t=='x'){
int g;
cin>>g;
if(n2.count(g)) n2.erase(g);
else n2.insert(g);
}
}
}
signed main(){
ios::sync_with_stdio(0);cin.tie(0);
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 7788kb
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: 7796kb
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: 536ms
memory: 58384kb
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: 434ms
memory: 43328kb
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 67280th lines differ - expected: '4280800', found: '100000200'