QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#303520 | #7685. Barkley II | ivaziva | Compile Error | / | / | C++17 | 2.5kb | 2024-01-12 17:45:21 | 2024-01-12 17:45:21 |
Judging History
answer
include <bits/stdc++.h>
using namespace std;
#define MAXN 500010
long long niz[MAXN];
vector<long long> pozicije[MAXN];
long long bit[MAXN];
long long last_visit[MAXN];
vector<pair<long long,long long>> query[MAXN];
void update(long long x,long long val,long long n)
{
for (long long i=x;i<=n;i+=(i&(-i))) bit[i]+=val;
}
long long sol(long long x)
{
long long br=0;
for (long long i=x;i>=1;i-=(i&(-i))) br+=bit[i];
return br;
}
void answer_queries(long long n)
{
for (long long i=1;i<=n;i++) bit[i]=0;
for (long long i=1;i<=n;i++) last_visit[i]=-1;
long long ans=-LLONG_MAX;
for (long long i=1;i<=n;i++)
{
if (last_visit[niz[i]]!=-1) update(last_visit[niz[i]],-1,n);
last_visit[niz[i]]=i;update(i,1,n);
long long s=query[i].size();
for (long long j=0;j<s;j++)
{
long long l=query[i][j].first;
long long mex=query[i][j].second;
long long val=sol(i)-sol(l-1);
ans=max(ans,val-mex);
}
}
cout<<ans<<endl;
}
int main()
{
ios_base::sync_with_stdio(false);
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long t;cin>>t;
for (long long z=0;z<t;z++)
{
///ZASTO OVO DAJE TLE JEBENI JEBAO VAS TL
long long n,m;cin>>n>>m;
for (long long i=1;i<=n;i++) cin>>niz[i];
for (long long i=1;i<=n;i++) pozicije[niz[i]].clear();
for (long long i=1;i<=n;i++) query[i].clear();
for (long long i=1;i<=n;i++) pozicije[niz[i]].push_back(i);
set<long long> sett;
for (long long i=1;i<=n;i++) sett.insert(niz[i]);
for (long long i=1;i<=n;i++)
{
if (sett.find(niz[i])==sett.end()) continue;
long long s=pozicije[i].size();
for (long long j=1;j<s;j++)
{
long long poz1=pozicije[i][j-1];
long long poz2=pozicije[i][j];
if (poz2-1>=poz1+1) query[poz2-1].push_back({poz1+1,i});
}
long long poz1=pozicije[i][0];
if (poz1-1>=1) query[poz1-1].push_back({1,i});
long long poz2=pozicije[i][s-1];
if (n>=poz2+1) query[n].push_back({poz2+1,i});
}
long long mex_niza=1;
for (auto p:sett)
{
if (p==mex_niza) mex_niza++;
}
query[n].push_back({1,mex_niza});
answer_queries(n);
}
}
Details
answer.code:1:1: error: ‘include’ does not name a type 1 | include <bits/stdc++.h> | ^~~~~~~ answer.code:8:1: error: ‘vector’ does not name a type 8 | vector<long long> pozicije[MAXN]; | ^~~~~~ answer.code:11:1: error: ‘vector’ does not name a type 11 | vector<pair<long long,long long>> query[MAXN]; | ^~~~~~ answer.code: In function ‘void answer_queries(long long int)’: answer.code:29:20: error: ‘LLONG_MAX’ was not declared in this scope 29 | long long ans=-LLONG_MAX; | ^~~~~~~~~ answer.code:1:1: note: ‘LLONG_MAX’ is defined in header ‘<climits>’; did you forget to ‘#include <climits>’? +++ |+#include <climits> 1 | include <bits/stdc++.h> answer.code:34:21: error: ‘query’ was not declared in this scope 34 | long long s=query[i].size(); | ^~~~~ answer.code:40:17: error: ‘max’ was not declared in this scope; did you mean ‘mex’? 40 | ans=max(ans,val-mex); | ^~~ | mex answer.code:43:5: error: ‘cout’ was not declared in this scope 43 | cout<<ans<<endl; | ^~~~ answer.code:43:16: error: ‘endl’ was not declared in this scope 43 | cout<<ans<<endl; | ^~~~ answer.code: In function ‘int main()’: answer.code:48:5: error: ‘ios_base’ has not been declared 48 | ios_base::sync_with_stdio(false); | ^~~~~~~~ answer.code:49:5: error: ‘ios’ has not been declared 49 | ios::sync_with_stdio(false); | ^~~ answer.code:50:5: error: ‘cin’ was not declared in this scope 50 | cin.tie(0); | ^~~ answer.code:51:5: error: ‘cout’ was not declared in this scope 51 | cout.tie(0); | ^~~~ answer.code:58:38: error: ‘pozicije’ was not declared in this scope 58 | for (long long i=1;i<=n;i++) pozicije[niz[i]].clear(); | ^~~~~~~~ answer.code:59:38: error: ‘query’ was not declared in this scope 59 | for (long long i=1;i<=n;i++) query[i].clear(); | ^~~~~ answer.code:60:38: error: ‘pozicije’ was not declared in this scope 60 | for (long long i=1;i<=n;i++) pozicije[niz[i]].push_back(i); | ^~~~~~~~ answer.code:61:9: error: ‘set’ was not declared in this scope 61 | set<long long> sett; | ^~~ answer.code:61:13: error: expected primary-expression before ‘long’ 61 | set<long long> sett; | ^~~~ answer.code:62:38: error: ‘sett’ was not declared in this scope 62 | for (long long i=1;i<=n;i++) sett.insert(niz[i]); | ^~~~ answer.code:65:17: error: ‘sett’ was not declared in this scope 65 | if (sett.find(niz[i])==sett.end()) continue; | ^~~~ answer.code:66:25: error: ‘pozicije’ was not declared in this scope 66 | long long s=pozicije[i].size(); | ^~~~~~~~ answer.code:71:37: error: ‘query’ was not declared in this scope 71 | if (poz2-1>=poz1+1) query[poz2-1].push_back({poz1+1,i}); | ^~~~~ answer.code:74:28: error: ‘query’ was not declared in this scope 74 | if (poz1-1>=1) query[poz1-1].push_back({1,i}); | ^~~~~ answer.code:76:28: error: ‘query’ was not declared in this scope 76 | if (n>=poz2+1) query[n].push_back({poz2+1,i}); | ^~~~~ answer.code:79:21: error: ‘sett’ was not declared in this scope 79 | for (auto p:sett) | ^~~~ answer.code:83:9: error: ‘query’ was not declared in this scope 83 | query[n].push_back({1,mex_niza}); | ^~~~~