QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#307236#6540. Beautiful SequenceyllcmWA 0ms10224kbC++142.4kb2024-01-18 11:03:522024-01-18 11:03:53

Judging History

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

  • [2024-01-18 11:03:53]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:10224kb
  • [2024-01-18 11:03:52]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define db double
#define ldb long double
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define FR first
#define SE second
using namespace std;
inline int read() {
  int x = 0; bool op = 0;
  char c = getchar();
  while(!isdigit(c))op |= (c == '-'), c = getchar();
  while(isdigit(c))x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
  return op ? -x : x;
}
const int N = 3e5 + 10;
const int INF = 1e9;
int n, tot;
int cnt[N], a[N], lsh[N];
void disc() {
  tot = 0;
  for(int i = 1; i <= n; i++)lsh[++tot] = a[i];
  sort(lsh + 1, lsh + 1 + tot);
  tot = unique(lsh + 1, lsh + 1 + tot) - (lsh + 1);
  for(int i = 1; i <= n; i++)
    a[i] = lower_bound(lsh + 1, lsh + 1 + tot, a[i]) - lsh;
  return ;
}
struct SGT {
  int mn[N << 2], tg[N << 2];
  void build(int k, int l, int r) {
    mn[k] = tg[k] = 0;
    if(l == r)return ;
    int mid = l + r >> 1;
    build(k << 1, l, mid); build(k << 1 | 1, mid + 1, r);
    return ;
  }
  void mark(int k, int w) {mn[k] += w; tg[k] += w;}
  void pushdown(int k) {
    if(!tg[k])return ;
    mark(k << 1, tg[k]);
    mark(k << 1 | 1, tg[k]);
    tg[k] = 0;
    return ;
  }
  void update(int k, int l, int r, int qx, int qy, int w) {
    if(l >= qx && r <= qy)return mark(k, w), void();
    int mid = l + r >> 1; pushdown(k);
    if(qx <= mid)update(k << 1, l, mid, qx, qy, w);
    if(qy > mid)update(k << 1 | 1, mid + 1, r, qx, qy, w);
    mn[k] = min(mn[k << 1], mn[k << 1 | 1]);
    return ;
  }
}sgt;
void solve() {
  n = read();
  for(int i = 1; i <= n; i++)a[i] = read();
  disc();
  for(int i = 1; i <= tot; i++)cnt[i] = 0;
  for(int i = 1; i <= n; i++)cnt[a[i]]++;
  vector<int> p;
  sgt.build(1, 1, tot);
  int res = 0;
  for(int i = tot; i; i--)
    p.pb(i), res++, sgt.update(1, 1, tot, 1, i, 1);
  for(auto u : p)printf("%d %d\n", u, cnt[u]);
  sort(p.begin(), p.end(), [&](int x, int y) {return cnt[x] < cnt[y];});
  for(auto u : p) {
    sgt.update(1, 1, tot, 1, u, -(cnt[u] + 1));
    if(sgt.mn[1] < 1)sgt.update(1, 1, tot, 1, u, cnt[u] + 1);
    else res--;
  }
  printf("%d\n", n - (res - 1));
  return ;
}
int main() { 
  int test = read();
  while(test--)solve();
  return 0;
}
/*
input:
1
10
9 4 4 5 2 5 3 8 2 5 
output:
7
input:
2
9
5 7 9 9 6 6 3 9 4 
10
4 8 10 6 5 9 2 8 8 7 
output:
6
6
input:
1
8
2 5 8 2 3 2 5 4 
output:
5
*/

详细

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 10224kb

input:

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

output:

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

result:

wrong answer 2nd numbers differ - expected: '4', found: '1'