QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#473020#8338. Quad Kingdoms Chess114514abcWA 127ms18948kbC++145.9kb2024-07-11 21:03:192024-07-11 21:03:19

Judging History

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

  • [2024-07-11 21:03:19]
  • 评测
  • 测评结果:WA
  • 用时:127ms
  • 内存:18948kb
  • [2024-07-11 21:03:19]
  • 提交

answer

#include<bits/stdc++.h>

using namespace std;

using ULL = unsigned long long;

const int N = 1e5 + 5;

mt19937_64 rnd(time(0));

ULL c[N];
int n[3], a[3][N], q, op, v, x, id;

struct S_TREE{
  struct Se_lin{
    struct Node{
      int l, r, maxx;
    }t[N * 4];
    void renew(int p){
      t[p].maxx = max(t[p * 2].maxx, t[p * 2 + 1].maxx);
    }
    void build(int p, int l, int r){
      t[p].l = l, t[p].r = r, t[p].maxx = 0;
      if(l == r){
        return;
      }
      int mid = (l + r) >> 1;
      build(p * 2, l, mid);
      build(p * 2 + 1, mid + 1, r);
    }
    void updata(int p, int l, int x){
      if(t[p].l == t[p].r){
        t[p].maxx = x;
        return;
      }
      int mid = (t[p].l + t[p].r) >> 1;
      if(l <= mid){
        updata(p * 2, l, x);
      }
      else{
        updata(p * 2 + 1, l, x);
      }
      renew(p);
    }
    int getsum(int p, int x){
      if(t[p].l == t[p].r){
        return t[p].l;
      }
      if(t[p * 2 + 1].maxx >= x){
        return getsum(p * 2 + 1, x);
      }
      return getsum(p * 2, x);
    }
  }T;
  struct seg_li{
    struct Node{
      int l, r;
      ULL lazy;
      ULL data;
    }t[N * 4];
    void tog(int p, ULL L){
      t[p].lazy += L;
      t[p].data += L;
    }
    void Lazy(int p){
      tog(p * 2, t[p].lazy);
      tog(p * 2 + 1, t[p].lazy);
      t[p].lazy = 0;
    }
    void build(int p, int l, int r){
      t[p].l = l, t[p].r = r, t[p].data = t[p].lazy = 0;
      if(l == r){
        return;
      }
      int mid = (l + r) >> 1;
      build(p * 2, l, mid);
      build(p * 2 + 1, mid + 1, r);
    }
    void updata(int p, int l, int r, ULL L){
      if(t[p].l >= l && t[p].r <= r){
        tog(p, L);
        return;
      }
      Lazy(p);
      int mid = (t[p].l + t[p].r) >> 1;
      if(l <= mid){
        updata(p * 2, l, r, L);
      }
      if(r > mid){
        updata(p * 2 + 1, l, r, L);
      }
    }
    ULL getsum(int p, int l){
      if(t[p].l == t[p].r){
        return t[p].data;
      }
      Lazy(p);
      int mid = (t[p].l + t[p].r) >> 1;
      if(l <= mid){
        return getsum(p * 2, l);
      }
      return getsum(p * 2 + 1, l);
    }
  }Hash_T;
  struct Node{
    int l, r, maxx, id, last, lastl;
  }t[N * 4];
  void renew(int p){
    //cout << Hash_T.getsum(1, 5) << '\n';
    //cout << Hash_T.getsum(1, 1) << '\n';
    //cout << Hash_T.getsum(1, 4) << '\n';
    //cout << t[p * 2].maxx << ' ' << t[p * 2 + 1].maxx << '\n';
      //Hash_T.updata(1, t[p * 2 + 1].lastl, t[p * 2 + 1].r, -t[p * 2 + 1].last);
      //cout << t[p * 2 + 1].lastl << ' ' << t[p * 2 + 1].r << " - " << t[p * 2 + 1].last << '\n';
    if(t[p * 2].maxx >= t[p * 2 + 1].maxx && t[p * 2 + 1].maxx != 1e9){
      //cout << t[p * 2].maxx << ' ' << t[p * 2 + 1].maxx << '\n';
      id = T.getsum(p * 2, t[p * 2 + 1].maxx);
      t[p * 2 + 1].last = Hash_T.getsum(1, id);
      //cout << t[p * 2 + 1].last << ' ' << id << '\n';
      //cout << t[p * 2 + 1].last << '\n';
      //cout << id << '\n';
      //cout << t[p * 2 + 1].last << '\n';
      //cout << t[p * 2 + 1].id << ' ' << t[p * 2 + 1].r << " + " << t[p * 2 + 1].last << '\n';
      Hash_T.updata(1, t[p * 2 + 1].id, t[p * 2 + 1].r, t[p * 2 + 1].last);
      t[p * 2 + 1].lastl = t[p * 2 + 1].id;
    }
    //cout << Hash_T.getsum(1, 4) << '\n';
    t[p].maxx = max(t[p * 2].maxx, t[p * 2 + 1].maxx);
    t[p].id = (t[p * 2].maxx == t[p].maxx ? t[p * 2].id : t[p * 2 + 1].id);
  }
  void build(int p, int l, int r){
    //cout << l <<' ' << r << '\n';
    t[p].l = l, t[p].r = r, t[p].maxx = 1e9, t[p].id = l, t[p].last = 0, t[p].lastl = l;
    if(l == r){
      return;
    }
    int mid = (l + r) >> 1;
    build(p * 2, l, mid);
    build(p * 2 + 1, mid + 1, r);
  }
  void emp(int x){
    Hash_T.build(1, 1, x);
    build(1, 1, x);
    T.build(1, 1, x);
  }
  void updata(int p, int l, int u, int v){  // 把 u 修改成 v
    //cout << l << ' ' << l << '\n';
    if(t[p].l == t[p].r){
      t[p].maxx = v;
      t[p].last = 0;
      //if(l == 5)cout << -c[u] + c[v] << ' ' << Hash_T.getsum(1, 5)<< '\n';
      Hash_T.updata(1, l, l, -c[u]);
      //if(l == 5)cout << Hash_T.getsum(1, 5) << '\n';
      Hash_T.updata(1, l, l, c[v]);
      //if(l == 5)cout << Hash_T.getsum(1, 5) << '\n';
      T.updata(1, l, v);
      //if(l == 5)cout << Hash_T.getsum(1, l) << '\n';
      //cout << c[v] << "\n\n";
      return;
    }
    Hash_T.updata(1, t[p * 2 + 1].lastl, t[p * 2 + 1].r, -t[p * 2 + 1].last);
    t[p * 2 + 1].last = 0;
    int mid = (t[p].l + t[p].r) >> 1;
    if(l <= mid){
      updata(p * 2, l, u, v);
    }
    else{
      updata(p * 2 + 1, l, u, v);
    }
    renew(p);
  }
  ULL modify(int p){
    return Hash_T.getsum(1, p);
  }
}T[3];

int main(){
  //ios::sync_with_stdio(0), cin.tie(0);
  for(int i = 1; i <= 100000; ++i){
    c[i] = rnd();
  }
  for(int i = 1; i <= 2; ++i){
    cin >> n[i];
    for(int j = 1; j <= n[i]; j++){
      cin >> a[i][j];
    }
  }
  for(int i = 1; i <= 2; ++i){
    T[i].emp(n[i]);
    for(int j = 1; j <= n[i]; j++){
      //cout << j << '\n';
      T[i].updata(1, j, 0, a[i][j]);
      //cout << "updata " << i << ' ' << j << '\n';
    }
  }
  /*
  for(int i = 1; i <= 2; ++i){
    for(int j = 1; j <= n[i]; ++j){
      cout << T[i].modify(j) << ' ';
    }
    cout << '\n';
  }
  */
  cin >> q;
  while(q--){
    cin >> op >> v >> x;
    T[op].updata(1, v, a[op][v], x);
    a[op][v] = x;
    cout << (T[1].modify(n[1]) == T[2].modify(n[2]) ? "YES\n" : "NO\n");
    /*
    for(int i = 1; i <= 2; ++i){
      for(int j = 1; j <= n[i]; j++){
        cout << a[i][j] << ' ';
      }
      cout << '\n';
    }
    for(int i = 1; i <= 2; ++i){
      for(int j = 1; j <= n[i]; ++j){
        cout << T[i].modify(j) << ' ';
      }
      cout << '\n';
    }
    */
  }
  return 0;
}
/*
6
1 3 1 2 1 2
6
2 1 3 3 3 1
1
2 4 2
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 18948kb

input:

5
1 2 3 4 5
5
5 4 3 2 1
8
1 1 5
1 4 2
1 2 4
1 5 1
1 5 5
2 1 4
2 3 5
2 5 5

output:

NO
NO
NO
YES
NO
NO
NO
YES

result:

ok 8 tokens

Test #2:

score: 0
Accepted
time: 99ms
memory: 18872kb

input:

1
2
6
2 1 1 1 1 1
200000
2 6 2
1 1 1
1 1 1
1 1 2
2 1 1
1 1 2
1 1 1
2 4 1
2 1 2
1 1 1
1 1 2
2 5 1
1 1 1
1 1 2
1 1 1
2 6 1
1 1 2
1 1 2
1 1 2
2 3 1
1 1 1
2 1 1
2 6 2
1 1 2
2 4 1
1 1 2
2 6 1
1 1 2
1 1 1
2 5 2
2 6 2
1 1 1
2 4 2
2 5 2
2 6 2
1 1 1
2 5 1
2 6 2
1 1 2
1 1 1
1 1 1
2 4 1
1 1 2
1 1 2
1 1 2
2 3 2...

output:

NO
NO
NO
NO
YES
YES
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
YES
YES
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
YES
YES
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
N...

result:

ok 200000 tokens

Test #3:

score: 0
Accepted
time: 127ms
memory: 18808kb

input:

6
2 1 1 2 1 2
1
1
200000
2 1 1
1 1 2
1 1 1
2 1 2
2 1 1
2 1 1
2 1 2
2 1 2
1 1 2
1 3 1
1 6 2
1 5 2
1 4 2
1 3 1
2 1 2
1 4 2
1 4 2
2 1 2
2 1 2
1 3 1
1 6 1
1 1 2
2 1 1
1 6 1
1 3 1
1 5 2
1 6 2
1 5 2
2 1 2
1 2 1
1 5 2
2 1 1
2 1 1
1 6 1
2 1 2
2 1 1
1 3 2
2 1 1
1 6 1
1 4 2
1 2 1
1 1 1
2 1 1
1 2 1
1 6 2
1 6 2...

output:

NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
...

result:

ok 200000 tokens

Test #4:

score: -100
Wrong Answer
time: 118ms
memory: 18820kb

input:

6
1 3 1 2 1 2
6
2 1 3 3 3 1
200000
2 4 2
1 2 1
1 6 2
2 3 2
1 1 1
1 6 2
1 6 2
1 3 2
2 6 1
2 4 3
1 1 2
2 5 2
2 6 2
2 3 1
1 4 3
1 3 1
2 5 2
2 4 2
2 1 3
1 1 1
2 2 2
2 4 2
1 5 3
1 6 3
2 6 3
1 5 3
2 5 3
2 4 1
2 4 2
1 1 2
1 6 1
2 6 1
1 2 3
1 1 3
1 1 1
2 6 3
2 4 1
1 4 2
2 2 1
1 3 1
1 1 3
1 1 3
1 4 3
1 3 3
2...

output:

NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
...

result:

wrong answer 27th words differ - expected: 'YES', found: 'NO'