QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#398974 | #8546. Min or Max 2 | 275307894a | WA | 475ms | 4072kb | C++14 | 3.1kb | 2024-04-25 20:35:49 | 2024-04-25 20:35:55 |
Judging History
answer
#include<bits/stdc++.h>
#define Gc() getchar()
#define Me(x,y) memset(x,y,sizeof(x))
#define Mc(x,y) memcpy(x,y,sizeof(x))
#define d(x,y) ((m)*(x-1)+(y))
#define R(n) (rnd()%(n)+1)
#define Pc(x) putchar(x)
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define eb emplace_back
#define all(x) x.begin(),x.end()
using namespace std;using ll=long long;using db=double;using lb=long db;using ui=unsigned;using ull=unsigned long long;using pii=pair<int,int>;
const int N=5000+5,M=1.5e8+5,K=1000+5,mod=998244353,Mod=mod-1;const db eps=1e-8;const int INF=1e9+7;mt19937 rnd(263082);
#define Tp template<typename T>
#define Ts template<typename T,typename... Ar>
namespace Debug{
Tp void _debug(char* f,T t){cerr<<f<<'='<<t<<endl;}
Ts void _debug(char* f,T x,Ar... y){while(*f!=',') cerr<<*f++;cerr<<'='<<x<<",";_debug(f+1,y...);}
#ifdef LOCAL
#define gdb(...) _debug((char*)#__VA_ARGS__,__VA_ARGS__)
#else
#define gdb(...) void()
#endif
}using namespace Debug;
int n,A[N],B[N],ans[N],pl[N];map<pii,int> f;
struct node{
int a,b;
node operator +(const node &B)const{
if(B.b==-1) return B;
if(b==-1) return (node){min(max(B.a,a),B.b),-1};
if(b<B.a) return (node){B.a,-1};
if(a>B.b) return (node){B.b,-1};
return (node){max(a,B.a),min(b,B.b)};
}
}C[N],l[N],r[N];
int f1[N],f2[N];
void work(node x,int A,int l,int r){
int mi=INF,mx=-INF;for(int i=l;i<=r;i++) mi=min(mi,f1[i]),mx=max(mx,f2[i]);
if(x.b==-1){
if(mi^INF) f[make_pair(A,x.a)]=1;
}else{
if(mi<=x.a) f[make_pair(A,x.a)]=1;
if(mx>=x.b) f[make_pair(A,x.b)]=1;
}
}
void calc(int *A,int *B){
int i,j;for(i=1;i<=n;i++) pl[A[i]]=i;
for(i=1;i<=n;i++) C[i]=(node){-INF,B[i]};
for(i=1;i<=n;i++){
int id=pl[i];
l[id]=accumulate(C+id,C+n+1,C[id]);
C[id]=(node){B[id],INF};
r[id]=accumulate(C+id,C+n+1,C[id]);
}
if(l[1].b==-1) f[make_pair(A[1],l[1].a)]=1;
else f[make_pair(A[1],l[1].b)]=1;
fill(f1+1,f1+n+1,INF);fill(f2+1,f2+n+1,-INF);
f1[A[1]]=f2[A[1]]=B[1];
for(i=2;i<=n;i++){
work(l[i],A[i],A[i],n);work(r[i],A[i],1,A[i]);
int mi=INF,mx=-INF;for(int j=A[i]+1;j<=n;j++) mi=min(mi,f1[j]),mx=max(mx,f2[j]);
if(mi^INF){
mi=min(mi,B[i]);mx=min(mx,B[i]);
f1[A[i]]=min(f1[A[i]],mi);f2[A[i]]=max(f2[A[i]],mx);
}
mi=INF,mx=-INF;for(int j=1;j<A[i];j++) mi=min(mi,f1[j]),mx=max(mx,f2[j]);
if(mi^INF){
mi=max(mi,B[i]);mx=max(mx,B[i]);
f1[A[i]]=min(f1[A[i]],mi);f2[A[i]]=max(f2[A[i]],mx);
}
for(int j=1;j<A[i];j++)if(f1[j]^INF) f1[j]=max(f1[j],B[j]),f2[j]=max(f2[j],B[j]);
for(int j=A[i]+1;j<=n;j++) if(f1[j]^INF) f1[j]=min(f1[j],B[j]),f2[j]=min(f2[j],B[j]);
}
}
void Solve(){
int i,j;scanf("%d",&n);f.clear();
for(i=1;i<=n;i++) scanf("%d",&A[i]);
for(i=1;i<=n;i++) scanf("%d",&B[i]);
calc(A,B);
map<pii,int> g;swap(g,f);for(auto i:g) f[make_pair(i.fi.se,i.fi.fi)]=1;
calc(B,A);
fill(ans,ans+n+1,0);
for(auto i:f) ans[abs(i.fi.fi-i.fi.se)]++;
for(i=0;i<n;i++) printf("%d%c",ans[i]," \n"[i==n-1]);
}
int main(){
int t=1;
scanf("%d",&t);
while(t--) Solve();
cerr<<clock()*1.0/CLOCKS_PER_SEC<<'\n';
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 4044kb
input:
4 2 1 2 2 1 5 2 4 1 5 3 2 4 1 5 3 5 1 2 3 4 5 5 4 3 2 1 8 5 8 3 4 2 7 1 6 4 6 3 8 5 1 2 7
output:
2 0 5 0 0 0 0 2 2 2 2 0 5 5 2 2 1 0 0 0
result:
ok 20 numbers
Test #2:
score: -100
Wrong Answer
time: 475ms
memory: 4072kb
input:
66664 7 4 2 6 5 7 1 3 6 5 3 1 4 7 2 10 6 8 10 7 5 1 4 3 9 2 5 10 3 8 6 7 2 9 1 4 9 3 2 4 8 7 6 9 1 5 8 1 2 9 6 7 4 3 5 10 4 3 9 6 7 2 10 1 8 5 3 5 4 1 2 7 10 9 6 8 5 3 4 1 2 5 5 1 3 2 4 5 2 4 3 5 1 2 3 1 4 5 6 2 6 1 3 4 5 6 4 5 1 3 2 10 10 1 2 7 5 8 4 3 9 6 9 4 2 3 6 1 7 8 5 10 5 1 2 4 5 3 4 1 2 5 3...
output:
4 4 2 2 1 0 0 5 6 3 2 2 1 0 0 0 0 4 6 3 3 1 0 0 0 0 4 4 4 3 2 1 0 0 0 0 5 3 0 0 0 2 2 2 2 0 3 3 3 1 0 0 5 7 4 2 1 0 0 0 0 0 5 1 0 0 0 6 3 0 0 0 0 3 3 2 0 0 5 4 2 1 0 0 0 3 2 3 2 0 0 4 6 3 0 0 0 0 3 4 3 2 1 0 0 3 2 2 2 2 2 2 1 0 4 5 3 1 0 0 0 3 4 3 2 3 3 1 0 0 0 8 6 1 2 0 0 0 0 7 8 4 1 1 0 0 0 0 0 5 ...
result:
wrong answer 18th numbers differ - expected: '5', found: '4'