Submission #891789

#TimeUsernameProblemLanguageResultExecution timeMemory
891789LCJLYGroup Photo (JOI21_ho_t3)C++14
0 / 100
0 ms348 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define ld long double #define show(x,y) cout << y << " " << #x << endl; #define show2(x,y,i,j) cout << y << " " << #x << " " << j << " " << #i << endl; #define show3(x,y,i,j,p,q) cout << y << " " << #x << " " << j << " " << #i << " " << q << " " << #p << endl; #define show4(x,y) for(auto it:x) cout << it << " "; cout << #y << endl; typedef pair<int,int>pii; typedef pair<pii,pii>pi2; void solve(){ int n; cin >> n; int arr[n]; for(int x=0;x<n;x++){ cin >> arr[x]; } int last[n+5]; memset(last,-1,sizeof(last)); int add[n+5]; memset(add,0,sizeof(add)); int counter=0; for(int x=0;x<n;x++){ int index=arr[x]; if(last[index+1]==-1){ last[index]=x; continue; } int prev=last[index+1]; //show2(prev,prev,x,x); int hold=x-prev+add[prev]-1; for(int y=x-1;y>=prev;y--){ add[y]--; } counter+=hold; last[index]=last[index+1]; } cout << counter; } int32_t main(){ ios::sync_with_stdio(0); cin.tie(0); //freopen("in.txt", "r", stdin); int t=1; //cin >> t; while(t--){ solve(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...