#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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Incorrect |
0 ms |
348 KB |
3rd lines differ - on the 1st token, expected: '0', found: '8' |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Incorrect |
0 ms |
348 KB |
3rd lines differ - on the 1st token, expected: '0', found: '8' |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Incorrect |
0 ms |
348 KB |
3rd lines differ - on the 1st token, expected: '0', found: '8' |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
3rd lines differ - on the 1st token, expected: '3304', found: '2744' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Incorrect |
0 ms |
348 KB |
3rd lines differ - on the 1st token, expected: '0', found: '8' |
10 |
Halted |
0 ms |
0 KB |
- |