QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#536125#4835. ModeAfterlifeCompile Error//C++174.0kb2024-08-28 18:48:182024-08-28 18:48:19

Judging History

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

  • [2024-08-28 18:48:19]
  • 评测
  • [2024-08-28 18:48:18]
  • 提交

answer

#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>
using namespace std;
const int maxn=2e5+1;
struct Gmx{
    int val[maxn],cnt[maxn];
    int n,all,mx;
    inline void init(int _n=0,int _all=0){
        n=_n;all=_all;
        memset(cnt,0,(n+1)*4);
        memset(val,0,(all+1)*4);
        cnt[0]=n;
        mx=0;
    }
    inline void add(int x){
        cnt[val[x]]--;
        val[x]++;
        cnt[val[x]]++;
        mx=max(mx,val[x]);
    }
    inline void del(int x){
        cnt[val[x]]--;
        val[x]--;
        cnt[val[x]]++;
        if(cnt[mx]==0)mx--;
    }
    inline int getmax(){
        return mx;
    }
}sol,sol2;
void gmax(int &x,int y){
    if(y>x)x=y;
}
int sum[maxn],now[maxn],pr[maxn];
vector<int>ve[maxn];
int a[maxn];
inline int read()
{
    int x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9')
    {
        if(ch=='-')
            f=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9')
    {
        x=x*10+ch-'0';
        ch=getchar();
    }
    return x*f;
}
typedef pair<int,int> pii;
int dynamic() { /// n*N + n*(>=N)
    ll ans = 1e18;
    map<int,int> mp;
    for(int i= 1;i <= cnt;i++) {
        if(ve[i].size()) mp[ve[i]]++ ;
    }
    vector<pair<int,int> > v;
    for(auto [x,y] : mp) v.push_back({x,y}) ;
    int cho = -1;
    int nxt = v.size() - 1 , cnt = 0;
    for(int i = n;i >= 1;i--) {
        if(nxt >=0 && v[nxt].first == i) cnt++ ;
        /// choose i
        if(1LL * i * n + 1LL * cnt * n < ans) {
            ans = 1LL * i * n + 1LL * cnt * n;
            cho = i;
        }
    }
    return cho ;
}
void solve()
{
    int n=read();
    vector<int> all;
    auto getid = [&](int x){
        return lower_bound(all.begin(),all.end(),x)-all.begin()+1;
    };
    for(int i=1;i<=n;i++)a[i]=read();
    for(int i=1;i<=n;i++)all.push_back(a[i]);
    sort(all.begin(),all.end());
    all.resize(unique(all.begin(),all.end())-all.begin());
    int cnt=(int)all.size();
    for(int i=1;i<=cnt;i++)ve[i].clear();
    for(int i=1;i<=n;i++)a[i]=getid(a[i]),ve[a[i]].push_back(i);
    
    int N=dynamic() ;

    vector<int> ans(cnt+1);
    for(int i=1;i<=cnt;i++)ans[i]=(int)ve[a[i]].size();
    for(int t=1;t<=N;t++){
        sol.init(n,cnt),sol2.init(n,cnt);
        for(int i=1;i<=n;i++)sol2.add(a[i]);
        int j=0;
        while(sol.mx<t&&j<n){++j;sol.add(a[j]);sol2.del(a[j]);}
        if(sol.mx!=t)break;
        for(int i=1;i<=n;i++){
            if(i>0)gmax(ans[a[i-1]],sol2.val[a[i-1]]+t);
            sol.del(a[i]);
            while(sol.mx<t&&j<n){
                j++;
                gmax(ans[a[j]],sol2.val[a[j]]+t);
                sol.add(a[j]);
                sol2.del(a[j]);
            }
            sol2.add(a[i]);
            if(sol.mx!=t)break;
        }
    }
    for(int z=1;z<=cnt;z++)if((int)ve[z].size()>=N){
        for(int i=1;i<=n;i++){
            sum[i]=sum[i-1]+(a[i]==z);
        }
        memset(pr,0,(cnt+1)*4);
        memset(now,0,(cnt+1)*4);
        for(int i=1;i<=n;i++)if(a[i]!=z){
            now[a[i]]+=sum[i]-sum[pr[a[i]]];
            // cout<<"z="<<z<<" i="<<i<<" now="<<now[a[i]]<<" ans="<<(int)ve[a[i]].size()+now[a[i]]<<endl;
            gmax(ans[a[i]],(int)ve[a[i]].size()+now[a[i]]);
            now[a[i]]--;
            if(now[a[i]]<0)now[a[i]]=0;
            pr[a[i]]=i;
        }
        memset(now,0,(cnt+1)*4);
        for(int i=1;i<=cnt;i++)pr[i]=n;
        for(int i=n;i>=1;i--)if(a[i]!=z){
            now[a[i]]+=sum[pr[a[i]]]-sum[i];
            // cout<<"z="<<z<<" i="<<i<<" now="<<now[a[i]]<<" ans="<<(int)ve[a[i]].size()+now[a[i]]<<endl;
            gmax(ans[a[i]],(int)ve[a[i]].size()+now[a[i]]);
            now[a[i]]--;
            if(now[a[i]]<0)now[a[i]]=0;
            pr[a[i]]=i;
        }
    }
    int max_ans=*max_element(ans.begin(),ans.end());
    printf("%d\n",max_ans);
    for(int i=1;i<=cnt;i++)if(ans[i]==max_ans)printf("%d\n",all[i-1]);
}
int main()
{
    int T=read();
    while(T--)solve();
    return 0;
}

詳細信息

answer.code: In function ‘int dynamic()’:
answer.code:58:5: error: ‘ll’ was not declared in this scope
   58 |     ll ans = 1e18;
      |     ^~
answer.code:60:23: error: ‘cnt’ was not declared in this scope; did you mean ‘int’?
   60 |     for(int i= 1;i <= cnt;i++) {
      |                       ^~~
      |                       int
answer.code:61:28: error: no match for ‘operator[]’ (operand types are ‘std::map<int, int>’ and ‘std::vector<int>’)
   61 |         if(ve[i].size()) mp[ve[i]]++ ;
      |                            ^
In file included from /usr/include/c++/13/map:63,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:152,
                 from answer.code:4:
/usr/include/c++/13/bits/stl_map.h:504:7: note: candidate: ‘std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type& std::map<_Key, _Tp, _Compare, _Alloc>::operator[](const key_type&) [with _Key = int; _Tp = int; _Compare = std::less<int>; _Alloc = std::allocator<std::pair<const int, int> >; mapped_type = int; key_type = int]’
  504 |       operator[](const key_type& __k)
      |       ^~~~~~~~
/usr/include/c++/13/bits/stl_map.h:504:34: note:   no known conversion for argument 1 from ‘std::vector<int>’ to ‘const std::map<int, int>::key_type&’ {aka ‘const int&’}
  504 |       operator[](const key_type& __k)
      |                  ~~~~~~~~~~~~~~~~^~~
/usr/include/c++/13/bits/stl_map.h:524:7: note: candidate: ‘std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type& std::map<_Key, _Tp, _Compare, _Alloc>::operator[](key_type&&) [with _Key = int; _Tp = int; _Compare = std::less<int>; _Alloc = std::allocator<std::pair<const int, int> >; mapped_type = int; key_type = int]’
  524 |       operator[](key_type&& __k)
      |       ^~~~~~~~
/usr/include/c++/13/bits/stl_map.h:524:29: note:   no known conversion for argument 1 from ‘std::vector<int>’ to ‘std::map<int, int>::key_type&&’ {aka ‘int&&’}
  524 |       operator[](key_type&& __k)
      |                  ~~~~~~~~~~~^~~
answer.code:67:17: error: ‘n’ was not declared in this scope
   67 |     for(int i = n;i >= 1;i--) {
      |                 ^
answer.code:70:42: error: ‘ans’ was not declared in this scope; did you mean ‘abs’?
   70 |         if(1LL * i * n + 1LL * cnt * n < ans) {
      |                                          ^~~
      |                                          abs