# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
316771 |
2020-10-28T01:10:01 Z |
caoash |
Kralj (COCI16_kralj) |
C++14 |
|
317 ms |
49016 KB |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
#define pb push_back
#define rsz resize
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define lb lower_bound
using pi = pair<int,int>;
#define f first
#define s second
#define mp make_pair
namespace output {
void pr(int x) {
cout << x;
}
void pr(long x) {
cout << x;
}
void pr(ll x) {
cout << x;
}
void pr(unsigned x) {
cout << x;
}
void pr(unsigned long x) {
cout << x;
}
void pr(unsigned long long x) {
cout << x;
}
void pr(float x) {
cout << x;
}
void pr(double x) {
cout << x;
}
void pr(long double x) {
cout << x;
}
void pr(char x) {
cout << x;
}
void pr(const char * x) {
cout << x;
}
void pr(const string & x) {
cout << x;
}
void pr(bool x) {
pr(x ? "true" : "false");
}
template < class T1, class T2 > void pr(const pair < T1, T2 > & x);
template < class T > void pr(const T & x);
template < class T, class...Ts > void pr(const T & t,
const Ts & ...ts) {
pr(t);
pr(ts...);
}
template < class T1, class T2 > void pr(const pair < T1, T2 > & x) {
pr("{", x.f, ", ", x.s, "}");
}
template < class T > void pr(const T & x) {
pr("{"); // const iterator needed for vector<bool>
bool fst = 1;
for (const auto & a: x) pr(!fst ? ", " : "", a), fst = 0;
pr("}");
}
void ps() {
pr("\n");
} // print w/ spaces
template < class T, class...Ts > void ps(const T & t,
const Ts & ...ts) {
pr(t);
if (sizeof...(ts)) pr(" ");
ps(ts...);
}
void pc() {
cout << "]" << endl;
} // debug w/ commas
template < class T, class...Ts > void pc(const T & t,
const Ts & ...ts) {
pr(t);
if (sizeof...(ts)) pr(", ");
pc(ts...);
}
#define dbg(x...) pr("[", #x, "] = ["), pc(x);
}
#ifndef ONLINE_JUDGE
using namespace output;
#else
using namespace output;
#define dbg(x...)
#endif
const int MX = 200005;
const int MOD = (int) (1e9 + 7);
const ll INF = (ll) 1e18;
template < int SZ > struct DSU {
int p[SZ], en[SZ];
void init() {
for (int i = 0; i < SZ; i++) {
p[i] = i;
en[i] = i;
}
}
int find(int x) {
return p[x] = (p[x] == x ? x : find(p[x]));
}
void merge(int u, int v) {
int a = find(u);
int b = find(v);
if (a != b) {
p[b] = a;
en[a] = en[b];
}
}
};
bool marked[MX];
DSU<MX> dsu;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int n; cin >> n;
vector<vi> a(n);
vi sx(n), sy(n);
for (int i = 0; i < n; i++) {
int x; cin >> x;
a[x - 1].pb(i);
}
for (int i = 0; i < n; i++) cin >> sx[i];
for (int i = 0; i < n; i++) cin >> sy[i];
dsu.init();
set<int> vals;
auto mark = [&] (int i) {
marked[i] = true;
int prev = (i - 1 + n) % n;
int nxt = (i + 1) % n;
if (marked[prev]) {
dsu.merge(prev, i);
}
if (marked[nxt]) {
dsu.merge(i, nxt);
}
};
for (int i = 0; i < n; i++) {
for (int j = 0; j < sz(a[i]); j++) {
if (!marked[i]) {
mark(i);
} else {
int lst = dsu.en[dsu.find(i)];
mark((lst + 1) % n);
}
}
}
int st = (dsu.en[dsu.find(0)] + 1) % n;
rotate(a.begin(), a.begin() + st, a.end());
rotate(sx.begin(), sx.begin() + st, sx.end());
set<int> dudes;
int ans = 0;
for (int i = 0; i < n; i++) {
// dbg(i, a[i]);
for (auto x : a[i]) dudes.insert(sy[x]);
auto it = dudes.lb(sx[i]);
if (it == dudes.end()) {
dudes.erase(dudes.begin());
} else {
++ans;
dudes.erase(it);
}
}
cout << ans << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
146 ms |
32492 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Runtime error |
141 ms |
31852 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
3 |
Runtime error |
174 ms |
38764 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
4 |
Runtime error |
179 ms |
39660 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
5 |
Runtime error |
232 ms |
39416 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
6 |
Runtime error |
260 ms |
40204 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
7 |
Runtime error |
299 ms |
46712 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
8 |
Runtime error |
271 ms |
43900 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
9 |
Runtime error |
317 ms |
49016 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
10 |
Runtime error |
286 ms |
43848 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |