萌新求助..不知道为什么WA了(QAQ)

P3088 [USACO13NOV] Crowded Cows S

还是WA(555555 ```cpp #include<iostream> #include<vector> #include<queue> #include<cstring> #include<cmath> #include<cstdio> #include<algorithm> using namespace std; const int maxn=100000; typedef long long LL; struct Cow { LL x;LL h; }a[maxn]; LL L[maxn],R[maxn]; LL stack[maxn]; LL N,D; bool cmp1(Cow k,Cow l) { return k.x<l.x; } //单调栈用于求某个数左/右边最近的比它大/小的数 int main(void) { cin.tie(0);std::ios::sync_with_stdio(false); freopen("P3088_2.in","r",stdin); cin>>N>>D; for(LL i=1;i<=N;i++) { cin>>a[i].x>>a[i].h; } sort(a+1,a+1+N,cmp1); // cout<<endl; // for(LL i=1;i<=N;i++) // { // cout<<a[i].x<<' '<<a[i].h<<endl; // } // cout<<endl; LL top=0; for(LL i=1;i<=N;i++) { while(top!=0&&a[stack[top]].h*2<=a[i].h) R[stack[top]]=i,top--; stack[++top]=i; } for(LL i=1;i<=top;i++) R[stack[i]]=N+1; top=0; for(LL i=N;i>=1;i--) { while(top!=0&&a[stack[top]].h*2<=a[i].h) L[stack[top]]=i,top--; stack[++top]=i; } for(LL i=1;i<=top;i++) L[stack[i]]=0; // for(LL i=1;i<=N;i++) // { // cout<<"R["<<i<<"]="<<R[i]<<"and"<<"L["<<i<<"]="<<L[i]<<endl; // } LL ans=0; for(LL i=1;i<=N;i++) { if(L[i]==0||R[i]==N+1) continue; if(a[R[i]].x-a[L[i]].x<=2*D) ans++; } cout<<ans<<endl; return 0; } ```
by 勇敢的菜鸡 @ 2020-07-15 15:04:14


要自闭了 ```cpp #include<iostream> #include<vector> #include<queue> #include<cstring> #include<cmath> #include<cstdio> #include<algorithm> using namespace std; const int maxn=100000; typedef long long LL; struct Cow { LL x;LL h; }a[maxn]; LL L[maxn],R[maxn]; LL stack[maxn]; LL N,D; bool cmp1(Cow k,Cow l) { return k.x<l.x; } //单调栈用于求某个数左/右边最近的比它大/小的数 int main(void) { cin.tie(0);std::ios::sync_with_stdio(false); // freopen("P3088_2.in","r",stdin); cin>>N>>D; for(LL i=1;i<=N;i++) { cin>>a[i].x>>a[i].h; } sort(a+1,a+1+N,cmp1); // cout<<endl; // for(LL i=1;i<=N;i++) // { // cout<<a[i].x<<' '<<a[i].h<<endl; // } // cout<<endl; LL top=0; for(LL i=1;i<=N;i++) { while(top!=0&&a[stack[top]].h*2<=a[i].h) R[stack[top]]=i,top--; stack[++top]=i; } for(LL i=1;i<=top;i++) R[stack[i]]=N+1; top=0; for(LL i=N;i>=1;i--) { while(top!=0&&a[stack[top]].h*2<=a[i].h) L[stack[top]]=i,top--; stack[++top]=i; } for(LL i=1;i<=top;i++) L[stack[i]]=0; // for(LL i=1;i<=N;i++) // { // cout<<"R["<<i<<"]="<<R[i]<<"and"<<"L["<<i<<"]="<<L[i]<<endl; // } LL ans=0; for(LL i=1;i<=N;i++) { if(L[i]==0||R[i]==N+1) continue; if(a[i].x-a[L[i]].x<=D&&a[R[i]].x-a[i].x<=D) ans++; } cout<<ans<<endl; return 0; } ```
by 勇敢的菜鸡 @ 2020-07-15 15:28:50


没事了.我是垃圾 ```cpp #include<iostream> #include<vector> #include<queue> #include<cstring> #include<cmath> #include<cstdio> #include<algorithm> using namespace std; const int maxn=1e5; typedef long long LL; LL q[maxn]; LL ans[maxn]; struct cow { LL x,h; }a[maxn]; bool cmp1(cow P,cow L) { return P.x<L.x; } int main(void) { cin.tie(0);std::ios::sync_with_stdio(false); // freopen("P3088_2.in","r",stdin); LL N,D;cin>>N>>D; for(LL i=1;i<=N;i++) cin>>a[i].x>>a[i].h; sort(a+1,a+1+N,cmp1); // for(LL i=1;i<=N;i++) // { // cout<<a[i].x<<' '<<a[i].h<<endl; // } // cout<<endl; LL head=1;LL tail=0; for(LL i=1;i<=N;i++) { while(head<=tail&&a[q[head]].x+D<a[i].x) head++; while(head<=tail&&a[q[tail]].h<=a[i].h) tail--; q[++tail]=i; if(a[i].h*2<=a[q[head]].h) { ans[i]++; } } memset(q,0,sizeof(q)); head=1;tail=0; for(LL i=N;i>=1;i--) { while(head<=tail&&a[q[head]].x>a[i].x+D) head++; while(head<=tail&&a[q[tail]].h<=a[i].h) tail--; q[++tail]=i; if(a[i].h*2<=a[q[head]].h) { ans[i]++; } } LL res=0; // for(LL i=1;i<=N;i++) cout<<ans[i]<<endl; for(LL i=1;i<=N;i++) if(ans[i]>=2) res++; cout<<res<<endl; return 0; } ```
by 勇敢的菜鸡 @ 2020-07-15 19:13:41


|