# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
370381 | jainbot27 | Kralj (COCI16_kralj) | C++17 | 2099 ms | 53348 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define pb push_back
#define ar array
#define all(x) x.begin(), x.end()
#define siz(x) (int)x.size()
#define FOR(x, y, z) for(int x = (y); x < (z); x++)
#define ROF(x, z, y) for(int x = (y-1); x >= (z); x--)
#define F0R(x, z) FOR(x, 0, z)
#define R0F(x, z) ROF(x, 0, z)
#define trav(x, y) for(auto&x:y)
using ll = long long;
using vi = vector<int>;
using vl = vector<long long>;
using pii = pair<int, int>;
using vpii = vector<pair<int, int>>;
template<class T> inline bool ckmin(T&a, T b) {return b < a ? a = b, 1 : 0;}
template<class T> inline bool ckmax(T&a, T b) {return b > a ? a = b, 1 : 0;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const char nl = '\n';
const int mxN = 5e5+10;
const int MOD = 1e9 + 7;
const long long infLL = 1e18;
int n;
int a[mxN];
int st[mxN];
int par[mxN];
vi v[mxN];
int nums[mxN];
int ans = 0;
int p(int q){
if(par[q]==q) return par[q];
return par[q]=p(par[q]);
}
void comb(int e1, int e2){
e1 = p(e1); e2 = p(e2);
par[e2] = e1;
}
int32_t main(){
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> n;
F0R(i, n){
par[i] = i;
int x; cin >> a[i]; a[i]--;
}
F0R(i, n){
cin >> st[i];
}
F0R(i, n){
int x; cin >> x;
v[a[i]].pb(x);
}
//cout << "WE GOT HERE" << endl;
int q = 0;
F0R(i, 2*n){
if(q>0){
comb((i-1)%n, i%n);
q--;
}
if(i < n) q += siz(v[i]);
}
//cout << "WE GOT HERE" << endl;
F0R(i, n){
//cout << par[i] << ' ';
nums[par[i]]++;
}
//cout << endl;
F0R(i, n){
set<int> al;
//cout << "I: " << i << endl;
FOR(j, i, i+nums[i]){
//cout << j << endl;
trav(x, v[j%n]){
al.insert(x);
//cout << x << endl;
}
auto it = al.lower_bound(st[j%n]);
if(it==al.end()) al.erase(al.begin());
else{
ans++;
al.erase(it);
}
}
}
cout << ans << nl;
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |