Submission #414743

#TimeUsernameProblemLanguageResultExecution timeMemory
414743jeqchoDancing Elephants (IOI11_elephants)C++17
0 / 100
9059 ms332 KiB
#include "elephants.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> pii; typedef vector<int> vi; typedef vector<pair<int,int>> vpi; #define FOR(i,a,b) for (int i = (a); i < (b); ++i) #define F0R(i,a) FOR(i,0,a) #define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i) #define R0F(i,a) ROF(i,0,a) #define trav(a,x) for (auto& a: x) #define pb push_back #define rsz resize #define sz(x) int(x.size()) #define all(x) begin(x), end(x) #define fi first #define se second int N; int L; int const n=5e4+3; int pre[n]; int nxt[n]; int X[n]; vpi x; set<pii>st; // subtask 1,2 void init(int N1, int L1, int X1[]) { L=L1; N = N1; F0R(i,N) { X[i]=X1[i]; x.pb({X[i],i}); st.insert({X[i],i}); } sort(all(x)); int prev=-1; trav(e,x) { pre[e.se]=prev; nxt[prev]=e.se; prev=e.se; } nxt[x.back().se]=N; } int update(int idx, int y) { int prev = pre[idx]; int next = nxt[idx]; pre[next]=prev; nxt[prev]=next; next = (*st.upper_bound({y,-1})).se; prev = pre[next]; nxt[idx] = next; pre[idx] = prev; nxt[prev] = idx; pre[next] = idx; X[idx]=y; int cnt=0; int b=-1; while(idx!=N) { if(X[idx]>b) { ++cnt; b = X[idx]+L; } idx=nxt[idx]; } return cnt; }
#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...