Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
52776 | AK2022071347 | 木薯与身高 | C++ | 解答错误 | 30 | 185 MS | 4108 KB | 954 | 2022-07-20 11:53:14 |
#include <cstdio> #include <algorithm> #include <cstring> #ifndef ONLINE_JUDGE #define FILEIO #endif // ONLINE_JUDGE #ifdef FILEIO FILE *infile=fopen("height.in","r"), *outfile=fopen("height.out","w"); #define scanf(x...) fscanf(infile,x) #define printf(x...) fprintf(outfile,x) #endif // FILEIO int n,x; int T[1000002]; inline int lowbit(int x) { return x&(-x); } inline void add(int x,int i) { while(x<=n+1) { T[x]=std::min(T[x],i); x+=lowbit(x); } } inline int query(int N) { int res=2147483647; while(N) { res=std::min(res,T[N]); N-=lowbit(N); } if(res>=n) return 0; return res; } int main() { scanf("%d",&n); memset(T,0x7f,sizeof(T)); int ans=0,tmp; for(int i=1;i<=n;++i) { scanf("%d",&x); tmp=query(n-x); if(tmp) ans+=i-tmp; add(n+1-x,i); } printf("%d\n",ans); #ifdef FILEIO fclose(infile); fclose(outfile); #undef scanf #undef printf #endif // FILEIO return 0; }