#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
kralj.cpp: In function 'int32_t main()':
kralj.cpp:55:13: warning: unused variable 'x' [-Wunused-variable]
55 | int x; cin >> a[i]; a[i]--;
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
753 ms |
45796 KB |
Output is correct |
2 |
Correct |
447 ms |
44516 KB |
Output is correct |
3 |
Correct |
583 ms |
52452 KB |
Output is correct |
4 |
Correct |
592 ms |
53348 KB |
Output is correct |
5 |
Execution timed out |
2077 ms |
32624 KB |
Time limit exceeded |
6 |
Execution timed out |
2089 ms |
32292 KB |
Time limit exceeded |
7 |
Execution timed out |
2078 ms |
36204 KB |
Time limit exceeded |
8 |
Execution timed out |
2099 ms |
34540 KB |
Time limit exceeded |
9 |
Execution timed out |
2095 ms |
37452 KB |
Time limit exceeded |
10 |
Execution timed out |
2095 ms |
34028 KB |
Time limit exceeded |