답안 #370382

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
370382 2021-02-23T22:32:52 Z jainbot27 Kralj (COCI16_kralj) C++17
56 / 140
2000 ms 43492 KB
#pragma GCC optimize("Ofast")  
#pragma GCC target("avx,avx2,fma") 
#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);
    }
    int q = 0;
    F0R(i, 2*n){
        if(q>0){
            comb((i-1)%n, i%n);
            q--;
        }
        if(i < n) q += siz(v[i]);
    }
    F0R(i, n){
        nums[par[i]]++;
    }
    F0R(i, n){
        set<int> al;
        FOR(j, i, i+nums[i]){
            trav(x, v[j%n]){
                al.insert(x);
            }
            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:57:13: warning: unused variable 'x' [-Wunused-variable]
   57 |         int x; cin >> a[i]; a[i]--;
      |             ^
# 결과 실행 시간 메모리 Grader output
1 Correct 779 ms 37348 KB Output is correct
2 Correct 449 ms 36716 KB Output is correct
3 Correct 575 ms 42772 KB Output is correct
4 Correct 615 ms 43492 KB Output is correct
5 Execution timed out 2025 ms 20716 KB Time limit exceeded
6 Execution timed out 2079 ms 21228 KB Time limit exceeded
7 Execution timed out 2097 ms 24300 KB Time limit exceeded
8 Execution timed out 2072 ms 23788 KB Time limit exceeded
9 Execution timed out 2087 ms 24556 KB Time limit exceeded
10 Execution timed out 2071 ms 22016 KB Time limit exceeded