QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#174912#5466. Permutation CompressionrealIyxiang#WA 2ms11656kbC++143.2kb2023-09-10 14:37:042023-09-10 14:37:04

Judging History

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

  • [2023-09-10 14:37:04]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:11656kb
  • [2023-09-10 14:37:04]
  • 提交

answer

#include <set>
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
#define rep(i, l, r) for (int i = l; i <= r; ++i)
#define dep(i, l, r) for (int i = r; i >= l; --i)
const int N = 2e5 + 5;
int n, m, c, T, ok;
int a[N], b[N], z[N], l[N], r[N], id[N], pos[N]; 
multiset <int> S; 

namespace ST {
  #define ls (p << 1)
  #define rs (p << 1 | 1)
  #define mid ((l + r) >> 1)
  struct node { int mi, mx; } t[N << 2]; 
  
  void build (int p, int l, int r) {
    t[p].mi = n + 1, t[p].mx = 0; 
    if(l == r) return ; 
    build(ls, l, mid), build(rs, mid + 1, r); 
  }
  void update (int p, int l, int r, int x, int k) {
    t[p].mi = min(t[p].mi, k); 
    t[p].mx = max(t[p].mx, k); 
    if(l == r) return ; 
    if(mid >= x) update(ls, l, mid, x, k) ;
    if(mid < x) update(rs, mid + 1, r, x, k); 
  }
  int qmax (int p, int l, int r, int x, int y) {
    if(x > y) return 0; 
    if(l >= x && r <= y) return t[p].mx; 
    int ans = 0; 
    if(mid >= x) ans = max(ans, qmax(ls, l, mid, x, y)); 
    if(mid < y) ans = max(ans, qmax(rs, mid + 1, r, x, y)); 
    return ans; 
  }
  int qmin (int p, int l, int r, int x, int y) {
    if(x > y) return n + 1; 
    if(l >= x && r <= y) return t[p].mi; 
    int ans = n + 1; 
    if(mid >= x) ans = min(ans, qmin(ls, l, mid, x, y)); 
    if(mid < y) ans = min(ans, qmin(rs, mid + 1, r, x, y)); 
    return ans; 
  }
}

namespace FT {
  int c1[N];
  long long c2[N]; 

  void reset () {
    rep(i, 1, n) c1[i] = c2[i] = 0; 
  }
  void add (int p, int k) {
    for (int i = p; i <= n; i += (i & (-i)))
      c1[i] += k, c2[i] += p * k; 
  }
  int qry (int p) {
    int ans1 = 0; long long ans2 = 0; 
    for (int i = p; i; i -= (i & (-i)))
      ans1 += c1[i], ans2 += c2[i]; 
    return 1ll * ans1 * (p + 1) - ans2; 
  }
  int qry (int l, int r) {
    return l > r ? 0 : qry(r) - qry(l - 1); 
  }
}

int main () {
  ios :: sync_with_stdio(0), cin.tie(0), cout.tie(0); 
  cin >> T;
  while (T--) {
    cin >> n >> m >> c, ok = 1; 
    rep(i, 1, n) cin >> a[i], pos[a[i]] = i;
    rep(i, 1, m) cin >> b[i]; 
    rep(i, 1, c) cin >> z[i]; 
    rep(i, 2, m) if(pos[b[i - 1]] > pos[b[i]]) { ok = 0; break ; }
    if(!ok || n - c > m) { puts("NO"); continue ; }
    S.clear(); 
    rep(i, 1, c) S.insert(z[i]); 
    rep(i, 1, n) l[i] = 0, r[i] = n + 1; 
    rep(i, 1, n) id[i] = 0; 
    rep(i, 1, m) id[b[i]] = 1; 
    m = 0; 
    rep(i, 1, n) if(!id[a[i]]) b[++m] = a[i]; 
    ST :: build(1, 1, n); 
    rep(i, 1, n) {
      l[i] = ST :: qmax(1, 1, n, a[i] + 1, n);
      if(id[a[i]]) ST :: update(1, 1, n, a[i], i); 
    }
    ST :: build(1, 1, n); 
    dep(i, 1, n) {
      r[i] = ST :: qmin(1, 1, n, a[i] + 1, n);
      if(id[a[i]]) ST :: update(1, 1, n, a[i], i); 
    }
    sort(b + 1, b + m + 1, [](int x, int y) { return x > y; }); 
    FT :: reset(); 
    rep(i, 1, m) {
      int x = pos[b[i]]; 
      ++l[x], --r[x]; 
      int len = r[x] - l[x] + 1 - FT :: qry(l[x], r[x]);
      auto it = S.upper_bound(len); 
      if(it != S.end() && (*it == *S.begin())) { ok = 0; break ; }
      --it, S.erase(it); 
      FT :: add(x, 1);   
    }
    if(ok) puts("YES"); 
    else puts("NO"); 
  }
  return 0; 
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 11648kb

input:

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

output:

YES
YES
NO

result:

ok 3 lines

Test #2:

score: -100
Wrong Answer
time: 1ms
memory: 11656kb

input:

100
2 1 2
2 1
2
1 1
2 1 2
1 2
1
2 2
2 1 1
1 2
1
2
6 1 5
3 4 2 5 6 1
3
5 2 1 1 1
6 1 6
2 1 3 6 4 5
1
4 1 2 2 1 4
3 3 2
2 1 3
2 1 3
2 2
1 1 1
1
1
1
1 1 1
1
1
1
2 1 2
2 1
2
1 2
4 4 3
2 1 3 4
2 1 3 4
4 3 1
1 1 1
1
1
1
6 5 1
6 2 5 4 3 1
6 2 4 3 1
4
1 1 1
1
1
1
6 5 3
3 6 1 4 5 2
3 6 1 4 2
3 3 4
4 3 4
3 4 ...

output:

YES
YES
YES
NO
NO
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
NO
YES
YES
YES
NO
YES
NO
YES
YES
NO
YES
YES
YES
YES
YES
NO
NO
YES
YES
YES
NO
NO
NO
NO
YES
NO
NO
YES
YES
YES
NO
YES
NO
YES
YES
YES
NO
YES
NO
NO
YES
YES
YES
YES
NO
YES
NO
YES
YES
YES
YES
YES
NO
YES
NO
YES
YES
YES
YES
YES
YES
YES
YES...

result:

wrong answer 4th lines differ - expected: 'YES', found: 'NO'