QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#246204#7729. Permutation Compression IIcomeintocalmTL 0ms13880kbC++171.7kb2023-11-10 17:16:042023-11-10 17:16:05

Judging History

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

  • [2023-11-10 17:16:05]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:13880kb
  • [2023-11-10 17:16:04]
  • 提交

answer

#include<bits/stdc++.h>
const int N = 1e6+7;
using namespace std;
const int U = 1e6;

int c[N], fr[N], ans[N], pos[N];
#define pii pair<int, int>

#define lbt(x) (x &(-x))
pii query(int x) {
  pii a; a.first = a.second = 0;
  if(!x) return a;
  while(x > 0) {
    if(c[x] > a.first) a.first = c[x], a.second = pos[x];
    else if(c[x] == a.first) a.second = min(a.second, pos[x]);
    x -= lbt(x);
  } return a;
}
void upd(int x, int a, int i) {
  while(x <= U) {
    //c[x] = max(c[x], a);
    if(a > c[x]) {
      c[x] = a;
      pos[x] = i;
    } else if(a == c[x]) pos[x] = min(i, pos[x]);
    x += lbt(x);
  }
}

int a[N], vis[N], ord[N];

int main() {
  int T;
  //scanf("%d", &T);
  //cin >> T;
  
  cin >> T;
  while(T--) {
    int n;
    cin >> n;
    int jump = 0;
    for(int i = 1; i <= n; i++) {
      cin >> a[i];
      ord[a[i]] = i;
      pii nx = query(a[i] - 1);
      ans[i] = nx.first + 1;
      fr[i] = nx.second;
      upd(a[i], ans[i], i);
      if(ans[i] > ans[jump]) jump = i;
    }
    int Len = ans[jump];
    vector<int> p;
    while(jump) {
      vis[jump] = 1;
      jump = fr[jump];
    }
    //reverse(q.begin(), q.end());
    set<int> s;
    int Del = 0;
    for(int i = 1; i <= n; i++) {
      if(vis[i]) {
        set<int>::iterator it;
        while((it = s.upper_bound(a[i])) != s.end()) {
          p.push_back(ord[*it]);
          s.erase(it);
        }
      }
      s.insert(a[i]);
    }
    printf("%d %d\n", Len, p.size());
    sort(p.begin(), p.end());
    for(auto &x : p) printf("%d ", x);
    printf("\n");
    for(int i = 0; i <= n; i++) a[i] = vis[i] = ord[i] = c[i] = fr[i] = ans[i] = pos[i] = 0;
  }
return 0;
}



/*
8
389 207 155 300 299 170 158 65
*/

详细

Test #1:

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

input:

2
3
3 1 2
3
1 2 3

output:

2 1
1 
3 0


result:

ok ok n = 3

Test #2:

score: -100
Time Limit Exceeded

input:

100000
7
2 6 7 1 4 3 5
6
1 5 6 3 2 4
3
1 2 3
3
2 1 3
14
9 6 13 10 4 7 5 14 1 12 8 3 2 11
3
1 2 3
14
1 9 3 14 5 7 4 6 12 2 8 11 13 10
8
7 1 3 6 2 5 8 4
16
9 3 4 8 7 16 10 6 11 1 14 2 13 12 5 15
3
3 1 2
33
9 10 23 3 16 1 19 32 25 4 5 31 28 7 22 27 30 8 6 17 2 14 13 29 20 33 26 18 24 11 12 15 21
2
2 1
...

output:

3 0

3 0

3 0

2 0


result: