QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#219342#5669. Traveling in Jade CityJenniferLing#WA 860ms28584kbC++175.7kb2023-10-19 12:44:492023-10-19 12:44:49

Judging History

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

  • [2023-10-19 12:44:49]
  • 评测
  • 测评结果:WA
  • 用时:860ms
  • 内存:28584kb
  • [2023-10-19 12:44:49]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;
const int INF=1e9;
#define N 2000006
int seg[N*4], arr[N];
int n, k, m, q, segn;
void build(int ind, int l, int r){
  if(l==r){
    seg[ind] = arr[l];
    return;
  }
  int mid = (l+r)>>1;
  build(ind*2, l, mid);
  build(ind*2+1, mid+1, r);
  seg[ind] = seg[ind*2]+seg[ind*2+1];
}
int query(int ind, int l, int r, int ql, int qr){
  if(r<ql || qr<l || r<l){
    return 0;
  }
  if(ql<=l && r<=qr){
    return seg[ind];
  }
  int mid = (l+r)>>1;
  return min(query(ind*2, l, mid, ql, qr)+query(ind*2+1, mid+1, r, ql, qr), INF);
}
void modify(int ind, int l, int r, int pos){
  if(l==r){
    if(seg[ind]==INF){
      seg[ind] = arr[l];
    }
    else{
      seg[ind] = INF;
    }
    return;
  }
  int mid = (l+r)>>1;
  if(pos<=mid)
    modify(ind*2, l, mid, pos);
  else{
    modify(ind*2+1, mid+1, r, pos);    
  }
  seg[ind] = min(seg[ind*2]+seg[ind*2+1], INF);
}
void solve() {
  cin >> n >> k >> m >> q;
  segn = n+m+1;
  for(int i=1; i<=n; ++i){
    cin >> arr[i];
  }
  for(int i=n+1; i<=n+1+m; ++i){
    cin >> arr[i];
  }
  build(1, 1, segn);
  while(q--){
    char typ; cin >> typ;
    if(typ=='q'){
      int a, b; cin >> a >> b;
      if(b<a){
        swap(a, b);
      }
      if(a==b){
        cout << "0\n";
      }
      else{
        //a<b
        int tmpans;
        if(a>k && b<=n){ // 1
          tmpans = min(query(1, 1, segn, a, b-1), min(query(1, 1, segn, 1, a-1)+query(1, 1, segn, b, n), query(1, 1, segn, b, n+m+1)+query(1, 1, segn, k, a-1)));
        }
        else if(b<k){ // 2
          tmpans = min(query(1, 1, segn, a, b-1), min(query(1, 1, segn, 1, a-1)+query(1, 1, segn, b, n), query(1, 1, segn, b, k-1)+query(1, 1, segn, 1, a-1)+query(1, 1, segn, n+1, n+m+1)));
        }
        else if(a<k && (k<b && b<=n)){ // 3
          int ans1 = query(1, 1, segn, 1, a-1)+query(1, 1, segn, b, n);
          int ans2 = query(1, 1, segn, a, b-1);
          int ans3 = query(1, 1, segn, a, k-1)+query(1, 1, segn, b, n+1+m);
          int ans4 = query(1, 1, segn, 1, a-1)+query(1, 1, segn, n+1, n+m+1)+query(1, 1, segn, k, b-1);
          tmpans = min(ans1, min(ans2, min(ans3, ans4)));
        }
        else if(a==1 && b==k){ // 4
          int ans1 = query(1, 1, segn, 1, k-1);
          int ans2 = query(1, 1, segn, k, n);
          int ans3 = query(1, 1, segn, n+1, n+1+m);
          tmpans = min(ans1, min(ans2, ans3));
        }
        else if(a==1 && b<k){ // 5
          int ans1 = query(1, 1, segn, a, b-1);
          int ans2 = query(1, 1, segn, b, n);
          int ans3 = query(1, 1, segn, b, k-1)+query(1, 1, segn, n+1 ,n+m+1);
          tmpans = min(ans1, min(ans2, ans3));
        }
        else if(a==1 && (k<b && b<=n)){ // 6
          int ans1 = query(1, 1, segn, b, n);
          int ans2 = query(1, 1, segn, a, b-1);
          int ans3 = query(1, 1, segn, k, b-1)+query(1, 1, segn, n+1, n+1+m);
          tmpans = min(ans1, min(ans2, ans3));
        }
        else if(a<k && b==k){
          int ans1 = query(1, 1, segn, a, b-1);
          int ans2 = query(1,1 , segn, 1, a-1)+query(1, 1, segn, b, n);
          int ans3 = query(1, 1, segn, 1, a-1)+query(1, 1, segn, n+1, n+1+m);
          tmpans = min(ans1, min(ans2, ans3));
        }
        else if(a==k && b<=n){ // 8
          int ans1 = query(1, 1, segn, a, b-1);
          int ans2 = query(1, 1, segn, 1, a-1)+query(1, 1, segn, b, n);
          int ans3 = query(1, 1, segn, b, n)+query(1, 1, segn, n+1, n+m+1);
          tmpans = min(ans1, min(ans2, ans3));
        }
        else if((k<a && a<=n) && n<b){ // 9
          int ans1 = query(1, 1, segn, a, n)+query(1, 1, segn, n+1, b);
          int ans2 = query(1, 1, segn, k, a-1)+query(1, 1, segn, b+1, n+1+m);
          int ans3 = query(1, 1, segn, 1, k-1)+query(1, 1, segn, a, n)+query(1, 1, segn, b+1, n+1+m);
          int ans4 = query(1, 1, segn, 1, a)+query(1, 1, segn, n+1, b);
          tmpans = min(ans1, min(ans2, min(ans3, ans4)));
        }
        else if(a<k && n<b){
          int ans1 = query(1, 1, segn, 1, a-1)+query(1, 1, segn, n+1, b);
          int ans2 = query(1, 1, segn, a, k-1)+query(1, 1, segn, b+1, n+1+m);
          int ans3 = query(1, 1, segn, 1, a-1)+query(1, 1, segn, k, n)+query(1, 1, segn, b+1, n+1+m);
          int ans4 = query(1, 1, segn, a, b);
          tmpans = min({ans1, ans2, ans3, ans4});
        }
        else if(a==1 && n<b){
          int ans1 = query(1, 1, segn, n+1, b);
          int ans2 = query(1, 1, segn, k, n)+query(1, 1, segn, b+1, n+1+m);
          int ans3 = query(1, 1, segn, 1, k-1)+query(1, 1, segn, b+1, n+m+1);
          tmpans = min({ans1, ans2, ans3});
        }
        else if(a==k && n<b){// 12
          int ans1 = query(1, 1, segn, b+1, n+1+m);
          int ans2 = query(1, 1, segn, n+1, b)+query(1, 1, segn, 1, k-1);
          int ans3 = query(1, 1, segn, n+1, b)+query(1, 1, segn, k ,n);
          tmpans = min({ans1, ans2, ans3});
        }
        else if(n<a){
          int ans1 = query(1, 1, segn, a+1, b);
          int ans2 = query(1, 1, segn, 1, k-1)+query(1, 1, segn, n+1, a)+query(1, 1, segn, b+1, n+1+m);
          int ans3 = query(1, 1, segn, k, a)+query(1, 1, segn, b+1, n+1+m);
          tmpans = min({ans1, ans2, ans3});
        }
        else {
          assert(false);
        }
        if(tmpans>=INF){
          cout << "impossible\n";
        }
        else{
          cout << tmpans << '\n';
        }
      }
    }
    else if(typ=='x'){
      int tmp; cin >> tmp; tmp+=n+1;
      modify(1, 1, segn, tmp);
    }
    else{// c
      int tmp; cin >> tmp;
      modify(1, 1, segn, tmp);
    }
  }
}

signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 5756kb

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: 860ms
memory: 28584kb

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
-2094967096
impossible
-2094967096
impossible
impossible
impossible
impossible
impossible
29295200
impossible
22163200
impossible
impossible
impossible
11422200
impossible
62579800
impossible
35339400
-2094967096
20157200
impossible
impossible
impossible
-2094...

result:

wrong answer 5th lines differ - expected: 'impossible', found: '-2094967096'