Submission #1075653

#TimeUsernameProblemLanguageResultExecution timeMemory
1075653edogawa_somethingAncient Books (IOI17_books)C++17
0 / 100
1 ms348 KiB
#include "books.h" #include<bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<ll> vii; typedef pair<ll,ll> pii; #define F first #define S second #define all(v) v.begin(),v.end() #define pb push_back ll n; ll sz=1; struct segtree { vii val; void init(ll x) { sz=1; while(sz<x) sz*=2; val.clear(); val.resize(2*sz); } void update(ll i,ll v,ll x=0,ll lx=0,ll rx=sz) { if(rx-lx==1) { val[x]=v; return; } ll mid=((lx+rx)>>1); if(i<mid) update(i,v,x*2+1,lx,mid); else update(i,v,x*2+2,mid,rx); val[x]=val[x*2+1]+val[x*2+2]; } ll query(ll l,ll x=0,ll lx=0,ll rx=sz) { if(lx>=l) return val[x]; if(rx<=l) return 0; ll mid=((lx+rx)>>1); return query(l,x*2+1,lx,mid)+query(l,x*2+2,mid,rx); } }seg; long long minimum_walk(vector<int> p, int s) { n=p.size(); ll res=0; seg.init(n); for(int i=0;i<n;i++) { if(p[i]>i) seg.update(p[i],1); seg.update(i,0); res+=seg.query(i+1)*2; } for(int i=0;i<n;i++) { if(p[i]==i) res+=2; else break; } return res; }
#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...