답안 #225830

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
225830 2020-04-21T19:18:38 Z osaaateiasavtnl Kralj (COCI16_kralj) C++14
140 / 140
619 ms 43368 KB
#include<bits/stdc++.h>
using namespace std;
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcount
#define ll long long
#define mp make_pair
#define f first
#define s second
#define Time (double)clock()/CLOCKS_PER_SEC 
const int N = 5e5 + 7;
int a[N], p1[N], p2[N];
vector <int> add[N]; 
signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    #define endl '\n'
    ios_base::sync_with_stdio(0); cin.tie(0);
    #endif
    int n;
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
    }   
    for (int i = 1; i <= n; ++i)
        cin >> p1[i];
    for (int i = 1; i <= n; ++i) {
        cin >> p2[i];
        add[a[i]].app(p2[i]);
    }                
    ii best = mp(N, N);
    int b = 0;
    for (int i = 1; i <= n; ++i) {
        b += add[i].size();
        --b;
        best = min(best, mp(b, i));
    }       
    int start = best.s + 1;
    if (start == n + 1)
        start = 1;
    int ans = 0;
    set <int> s;
    for (int sh = 0; sh < n; ++sh) {
        int i = start + sh;
        if (i > n)
            i -= n;
        for (int x : add[i])
            s.insert(x);
        auto t = s.upper_bound(p1[i]);
        if (t == s.end()) {
            s.erase(s.begin());
        }   
        else {
            ++ans;
            s.erase(t);
        }
    }
    cout << ans << endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 619 ms 37224 KB Output is correct
2 Correct 378 ms 36576 KB Output is correct
3 Correct 511 ms 42600 KB Output is correct
4 Correct 584 ms 43368 KB Output is correct
5 Correct 365 ms 20856 KB Output is correct
6 Correct 320 ms 21240 KB Output is correct
7 Correct 411 ms 23928 KB Output is correct
8 Correct 329 ms 23544 KB Output is correct
9 Correct 449 ms 24568 KB Output is correct
10 Correct 374 ms 22008 KB Output is correct