QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#246220#7729. Permutation Compression IIcomeintocalmCompile Error//C++171.8kb2023-11-10 17:27:162023-11-10 17:27:16

Judging History

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

  • [2023-11-10 17:27:16]
  • 评测
  • [2023-11-10 17:27:16]
  • 提交

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) {
  if(!x) return;
  while(x <= n) {
    //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 n;
int a[N], vis[N], ord[N];

int main() {
  int T;
  //scanf("%d", &T);
  //cin >> T;
  
  cin >> T;
  vector<int> p;
  set<int> s;
  while(T--) {
    
    scanf("%d", &n);
    int jump = 0;
    for(int i = 1; i <= n; i++) {
      scanf("%d", &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];
    
    while(jump) {
      vis[jump] = 1;
      jump = fr[jump];
    }
    //reverse(q.begin(), q.end());
    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;
    p.clear();
    s.clear();
  }
return 0;
}



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

Details

answer.code: In function ‘void upd(int, int, int)’:
answer.code:21:14: error: ‘n’ was not declared in this scope
   21 |   while(x <= n) {
      |              ^
answer.code: In function ‘int main()’:
answer.code:71:17: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘std::vector<int>::size_type’ {aka ‘long unsigned int’} [-Wformat=]
   71 |     printf("%d %d\n", Len, p.size());
      |                ~^          ~~~~~~~~
      |                 |                |
      |                 int              std::vector<int>::size_type {aka long unsigned int}
      |                %ld
answer.code:43:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   43 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
answer.code:46:12: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   46 |       scanf("%d", &a[i]);
      |       ~~~~~^~~~~~~~~~~~~