P4378 [USACO18OPEN] Out of Sorts S
不可以 val-pos cuase not 1234....
计算的是左移,右移 一轮 就可以实现 -》.....
/* 10 7 7 7 7 7 6 6 6 6 6 6 */ #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #include<bits/stdc++.h> #define ll long long #define ddd printf("--------------debug\n"); using namespace std; int n,ans=0; struct node{ int val,pos; }a[200010]; bool cmp(node x,node y){ return x.val<y.val || (x.val==y.val&&x.pos<y.pos);//7766 } int main() { ios::sync_with_stdio(false); cin.tie(0); cin>>n; for(int i=1;i<=n;i++) cin>>a[i].val,a[i].pos=i; sort(a+1,a+1+n,cmp); //for(int i=1;i<=n;i++) cout<<a[i].val; for(int i=1;i<=n;i++){ ans=max(ans,a[i].pos-i);//不可以 val-pos cuase not 1234.... }//计算的是左移,右移 一轮 就可以实现 -》..... cout<<ans+1<<'\n'; return 0; }

浙公网安备 33010602011771号