QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#253042 | #7685. Barkley II | ucup-team1321# | WA | 45ms | 3448kb | C++23 | 2.2kb | 2023-11-16 16:59:23 | 2023-11-16 16:59:24 |
Judging History
answer
#include <bits/stdc++.h>
#ifndef LOCAL
#define debug(...) 42
#else
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#endif
#define rep1(a) for (int i = 0; i < a; i++)
#define rep2(i, a) for (int i = 0; i < a; i++)
#define rep3(i, a, b) for (int i = a; i < b; i++)
#define rep4(i, a, b, c) for (int i = a; i < b; i += c)
#define overload4(a, b, c, d, e, ...) e
#define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define pb emplace_back
using namespace std;
template <typename T, typename T2> void cmin(T &x, const T2 &y) {
x = x < y ? x : y;
}
template <typename T, typename T2> void cmax(T &x, const T2 &y) {
x = x > y ? x : y;
}
using ll = long long;
using vi = vector<int>;
using pii = pair<int, int>;
template <class T> using vc = vector<T>;
template <class T> using pq = priority_queue<T>;
template <class T> using pqg = priority_queue<T, vector<T>, greater<T>>;
mt19937 rng(time(NULL));
const int inf = 1000000000;
const ll lnf = 1000000000000000000;
#define sz(x) int((x).size())
#define all(x) begin(x), end(x)
#define fi first
#define se second
const int N=5e5+5;
int pos[N];
void solve() {
int n, m;
cin >> n >> m;
vi a(n);
rep(i,n)cin>>a[i];
rep(i,n)pos[a[i]]=-1;
vector<int> t(n*2);
auto upd=[&](int x,int v){
x+=n;
while(x){
t[x]+=v;
x/=2;
}
return;
};
auto query=[&](int l,int r){
int ans=0;
for(l+=n,r+=n;l<r;l/=2,r/=2){
if(l&1)ans+=t[l++];
if(r&1)ans+=t[--r];
}
return ans;
};
vc<vc<pii>> querys(n);
rep(i,n){
int l=pos[a[i]]+1;
int r=i-1;
if(l<=r){
querys[r].pb(l,-a[i]);
}
pos[a[i]]=i;
}
rep(i,n){
int l=pos[a[i]]+1;
int r=n-1;
if(l<=r){
querys[r].pb(l,-a[i]);
}
}
rep(i,n)pos[a[i]]=-1;
int ans=-1;
rep(i,n){
if(pos[a[i]]!=-1)upd(pos[a[i]],-1);
pos[a[i]]=i,upd(i,1);
for(auto [j,v]:querys[i])cmax(ans,query(j,i+1)+v);
}
cout<<ans<<"\n";
rep(i,n)pos[a[i]]=-1;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t = 1;
cin >> t;
while (t--) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3444kb
input:
2 5 4 1 2 2 3 4 5 10000 5 2 3 4 1
output:
2 3
result:
ok 2 number(s): "2 3"
Test #2:
score: -100
Wrong Answer
time: 45ms
memory: 3448kb
input:
50000 10 19 12 6 1 12 11 15 4 1 13 18 10 8 8 7 6 7 6 2 2 3 4 8 10 6 3 2 6 6 5 2 3 4 5 6 10 11 6 3 7 9 2 1 2 10 10 4 10 6 6 1 2 6 1 1 3 4 2 1 10 9 8 5 3 9 1 7 5 5 1 1 10 5 1 4 3 2 5 4 5 3 5 2 10 14 3 8 12 10 4 2 3 13 7 3 10 14 5 5 12 2 8 1 13 9 8 5 10 7 5 5 6 6 1 5 3 7 3 4 10 7 5 1 4 6 1 6 4 3 7 5 10...
output:
3 1 2 4 2 3 3 3 3 3 4 5 2 3 -1 3 1 3 7 6 3 3 -1 2 4 4 6 2 3 0 6 1 2 2 2 5 3 3 3 3 2 5 2 1 3 3 2 3 1 4 2 2 4 4 2 2 5 3 2 1 4 3 3 3 2 3 0 4 7 6 2 2 4 3 3 4 -1 6 3 3 3 3 4 0 1 1 4 5 4 5 3 1 1 2 1 3 3 4 4 3 4 2 1 3 4 4 3 -1 3 4 3 5 4 4 2 4 6 4 4 5 3 4 5 1 4 3 3 3 3 -1 3 2 1 2 5 1 2 1 4 4 2 2 4 5 4 3 -1 ...
result:
wrong answer 1st numbers differ - expected: '6', found: '3'