Submission #643022

# Submission time Handle Problem Language Result Execution time Memory
643022 2022-09-21T04:37:51 Z ddy888 Baloni (COCI15_baloni) C++17
100 / 100
170 ms 57244 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("unroll-loops")
using namespace std;
using namespace __gnu_pbds;

using ll = long long;
#define pb push_back
#define fi first
#define si second
#define ar array
typedef pair<int,int> pi;
typedef tuple<int,int,int> ti;  
template<typename T> bool chmin(T &a, T b){return (b < a) ? a = b, 1 : 0;}
template<typename T> bool chmax(T &a, T b){return (b > a) ? a = b, 1 : 0;}
template<class key, class value = null_type, class cmp = less<key> >
using ordered_set = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());

void debug_out() {cerr<<endl;}
template <typename Head, typename... Tail>
void debug_out(Head _H, Tail... _T) {cerr<<" "<<to_string(_H);debug_out(_T...);}
#define debug(...) cerr<<"["<<#__VA_ARGS__<<"]:",debug_out(__VA_ARGS__)
const int MAXN = 1000010;

int n;
int arr[MAXN], f[MAXN];
set<int> pos[MAXN];

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin.exceptions(ios::badbit | ios::failbit);
    cin >> n;
    for (int i = 1; i <= n; ++i) cin >> arr[i];
    for (int i = n; i >= 1; --i) {
        int p = arr[i]-1;
        if ((int)pos[p].size()) {
            f[*pos[p].begin()] = 1;
            pos[p].erase(*pos[p].begin());
        }
        pos[arr[i]].insert(i);
    }
    int ans = 0;
    for (int i = 1; i <= n; ++i) ans += (f[i]==0);
    cout << ans;
    return 0;
}   
# Verdict Execution time Memory Grader output
1 Correct 23 ms 47316 KB Output is correct
2 Correct 26 ms 47368 KB Output is correct
3 Correct 23 ms 47372 KB Output is correct
4 Correct 24 ms 47324 KB Output is correct
5 Correct 131 ms 56508 KB Output is correct
6 Correct 170 ms 57244 KB Output is correct
7 Correct 146 ms 55320 KB Output is correct
8 Correct 139 ms 55152 KB Output is correct
9 Correct 150 ms 55820 KB Output is correct
10 Correct 145 ms 56064 KB Output is correct