#include "souvenirs.h"
#include<bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sm pair<vector<int>, long long>
using namespace std;
const int maxn = 5e5;
long long tree[4 * maxn];
long long a[maxn];
void build(int node, int start, int end){
if(start == end){
tree[node] = a[start];
}
else{
int mid = (start + end) / 2;
build(2 * node, start, mid);
build(2 * node + 1, mid + 1, end);
tree[2 * node] = tree[2 * node + 1] + tree[2 * node + 1];
}
}
int query(int node, int start, int end, int l, int r){
if(start > r || end < l) return 0;
if(start >= l && end <= l) return tree[node];
int mid = (start + end) / 2;
int l1 = query(2 * node, start, mid, l, r);
int r1 = query(2 * node + 1, mid + 1, end, l, r);
return l1 + r1;
}
void sub3(int n, long long P0){
sm T = transaction(P0 - 1);
if(T.ff.size() == 1){
long long p1 = P0 - 1 - T.ss;
transaction(p1 - 1);
transaction(p1 - 1);
}
else{
long long sm2 = P0 - 1 - T.ss;
transaction(sm2 / 2);
}
}
void buy_souvenirs(int N, long long P0){
long long p = P0;
if(N == 2){
transaction(p - 1);
return;
}
else if(N == 3){
sub3(N, P0);
return;
}
else if(P0 == N){
for(int i = N - 1; i >= 1; i--){
for(int j = 1; j <= N - i; j++){
transaction(i);
}
}
return;
}
else{
a[0] = P0;
for(int i = 0; i < N - 1; i++){
sm T = transaction(a[i] - 1);
if(T.ss == 1){
a[i + 1] = a[i] + 2;
}
else{
a[i + 1] = a[i] + 1;
}
}
build(1, 0, N - 1);
for(int i = 1; i < N; i++){
transaction(query(1, 0, N - 1, i, N - 1));
}
return;
}
return;
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |