# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
309606 | 2020-10-03T23:52:06 Z | andriakhvichia | Exercise Deadlines (CCO20_day1problem2) | C++14 | 4 ms | 512 KB |
#include<iostream> #include<vector> #include <queue> using namespace std; int n; //guramis kodi long long a[100001],s[100001]; int prev(int u) { return u&(u-1); } int next(int u) { return (u<<1)-(u&(u-1)); } long long getsum(int a, int b) { long long ans=0; while(b>0) { ans+=s[b]; b=prev(b); } a--; while(a>0) { ans-=s[a]; a=prev(a); } return ans; } void update(int u, long long d) { while(u<=n) { s[u]+=d; u=next(u); } } // int main() { vector<int>v[1000]; int array[1000]; cin>>n; //shemotana da vectoris sheqmna for(int i=1;i<=n;i++) { cin>>array[i]; } for(int i=1;i<=n;i++) { int k=array[i]; //cout<<"k="<<k<<" "<<"i="<<i<<endl; v[k].push_back(i); } //cout<<endl; for(int i=1;i<=n;i++) { a[i]=1; } for (int i=1;i<=n;i++)update(i,1); //TEST //mushaobs tu ara vectorebi /*for(int i=1;i<=n;i++) { vector<int>k=v[i]; cout<<i<<" - "; for(int j=0;j<k.size();j++) { cout<<k[j]<<" "; } cout<<endl; }*/ priority_queue<int>q; int x=n-1; vector<int>k=v[n]; for(int i=0;i<k.size();i++) { q.push(k[i]); } int ans=0; int l=1; while(l<n) { int mr=q.top(); q.pop(); //cout<<mr<<endl; if(x>=1) { vector<int>k=v[x]; for(int i=0;i<k.size();i++) { q.push(k[i]); } x--; } //cout<<"getsum("<<mr+1<<","<<n<<")="<<getsum(mr+1,n)<<endl; ans+=getsum(mr+1,n); update(mr,-1); if(q.empty()) { //cout<<"-1"<<endl; break; } l++; } cout<<ans<<endl; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Runtime error | 4 ms | 512 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Runtime error | 4 ms | 512 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
2 | Halted | 0 ms | 0 KB | - |