QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#614756#6701. BaoBao Loves Readingzqx#WA 0ms3668kbC++231.4kb2024-10-05 16:53:532024-10-05 16:53:55

Judging History

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

  • [2024-10-05 16:53:55]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3668kb
  • [2024-10-05 16:53:53]
  • 提交

answer

#include<bits/stdc++.h>
#define AC return 0;
#define int long long 
#define pii pair<int,int>
#define all(tar) tar.begin(),tar.end()
const int maxx=2e5+5;
const int mod=998244353; 
using namespace std;
int n,t;
struct Fenwick_tree
{
    static const int N = 3e5 + 10;

    int t[N];

    #define lowbit(x) (x & -x)

    void Add(int x, int v) 
    {
        for (int i = x; i <= n; i += lowbit(i))
            t[i] += v;
    }

    int Ask(int x) {
        int res = 0;
        for (int i = x; i > 0; i -= lowbit(i))
            res += t[i];
        return res;
    }

    int Query(int l, int r) 
    {
        return Ask(r) - Ask(l - 1);
    }
}bit;


signed main(){
   ios::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
   cin>>t;
   while(t--){
     cin>>n;
     vector<int>pre(n+1,0),ans(n+1,0);
     for(int i=1;i<=n;i++){
        bit.t[i]=0;
     }
     for(int i=1;i<=n;i++){
         int x;
         cin>>x;
         if(!pre[x]){
           ans[n]++; 
           pre[x]=i;
           bit.Add(i,1);
         }else {
           int sum=bit.Query(pre[x],i);
         //  cout<<i<<" "<<sum<<'\n';
           ans[sum-1]++;
           bit.Add(pre[x],-1);
           bit.Add(i,1);
           pre[x]=i;
         }
     }
     for(int i=n-1;i>=1;i--){
        ans[i]+=ans[i+1];
     }
     for(int i=1;i<=n;i++)cout<<ans[i]<<" ";
     cout<<'\n';
   }
   AC
}   

详细

Test #1:

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

input:

1
7
4 3 4 2 3 1 4

output:

7 6 5 4 4 4 4 

result:

wrong answer 1st lines differ - expected: '7 6 5 4 4 4 4', found: '7 6 5 4 4 4 4 '