QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#383380 | #7685. Barkley II | Giga_Cronos# | WA | 101ms | 3788kb | C++23 | 3.0kb | 2024-04-09 11:57:48 | 2024-04-09 11:57:48 |
Judging History
answer
// #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops",
// "omit-frame-pointer", "inline") #pragma GCC
// target("sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,popcnt,abm,mmx,avx,avx2,fma,tune=native")
// #pragma GCC option("arch=native", "no-zero-upper") // Enable AVX
/// UH Top
#include <bits/stdc++.h>
#define db(x) cerr << #x << ':' << (x) << '\n';
#define all(v) (v).begin(), (v).end()
#define allr(v) (v).rbegin(), (v).rend()
#define int ll
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
// typedef __int128_t int128;
typedef pair<ll, ll> pii;
typedef pair<ld, ll> pdi;
typedef pair<ld, ld> pdd;
typedef pair<ld, pdd> pdp;
typedef pair<string, ll> psi;
typedef pair<ll, string> pls;
typedef pair<string, string> pss;
typedef pair<ll, pii> pip;
typedef pair<pii, pii> ppp;
typedef complex<ld> point;
typedef vector<point> polygon;
typedef vector<ll> vi;
typedef pair<point, int> ppi;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
#define prec(n) \
cout.precision(n); \
cout << fixed
const ll mod = (1e9 + 7);
const ld eps = (1e-9);
const ll oo = (ll)(1e18 + 5);
#define pi acos(-1)
#define MAXN (ll)(5e5 + 5)
#define fs first
#define sc second
#define mid (L + R) / 2
#define pb push_back
#define sz(x) (int)((x).size())
int n, m;
struct ABI {
vector<vector<int>> abi;
int maxn;
ABI(int n){
maxn = n + 5;
abi.resize(maxn);
}
void update(int p, int v) {
while (p < maxn) {
abi[p].push_back(v);
p += (p & -p);
}
}
void build(vector<int> &a) {
int n = a.size();
for (int i = 0; i < n; i++)
update(i + 1, a[i]);
for (int i = 0; i < maxn; i++)
sort(all(abi[i]));
}
int query(int p, int l, int r) {
int ans = 0;
while (p) {
ans += upper_bound(all(abi[p]), r) - lower_bound(all(abi[p]), l);
p -= (p & -p);
}
return ans;
}
int query(int l, int r, int vl, int vr) {
if(r<l)return 0;
return query(r + 1, vl, vr) - query(l, vl, vr);
}
};
vi Pos[MAXN];
void problem() {
cin>>n>>m;
set<int> Vec;
vi AntP;
for(int i=0;i<n;i++){
int a;cin>>a;
Vec.insert(a);
if(sz(Pos[a])){
AntP.pb(Pos[a].back());
}else{
AntP.pb(-1);
}
Pos[a].pb(i);
}
ABI cosa(n);
cosa.build(AntP);
int ans=0;
for(auto a:Vec){
for(int i=0;i<sz(Pos[a]);i++){
int l,r;
if(i==0){
l=0,r=Pos[a][i]-1;
ans=max(ans,cosa.query(l,r,-1,l-1)-a);
}
if(i==sz(Pos[a])-1){
l=Pos[a][i]+1,r=n-1;
ans=max(ans,cosa.query(l,r,-1,l-1)-a);
}else{
l=Pos[a][i]+1,r=Pos[a][i+1]-1;
ans=max(ans,cosa.query(l,r,-1,l-1)-a);
}
}
Pos[a].resize(0);
}
cout<<ans<<'\n';
}
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int tc = 1;
cin>>tc;
while (tc--) {
problem();
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3788kb
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: 101ms
memory: 3508kb
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 0 3 1 3 7 6 3 3 0 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 0 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 0 3 4 3 5 4 4 2 4 6 4 4 5 3 4 5 1 4 3 3 3 3 0 3 2 1 2 5 1 2 1 4 4 2 2 4 5 4 3 0 6 6 3 ...
result:
wrong answer 1st numbers differ - expected: '6', found: '3'