Submission #988581

# Submission time Handle Problem Language Result Execution time Memory
988581 2024-05-25T08:05:48 Z ibsha Poklon (COCI17_poklon) C++17
0 / 140
609 ms 40560 KB
#include <bits/stdc++.h>
/*
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
*/
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define MOD ((1ull << 59) - 1)
#define endl '\n'
#define pb(v,i) (v).push_back(i)
#define vll vector<ll>
#define pll pair<ll,ll>

//__int128 fastpow(ll base,ll exp){__int128 result=1;while (exp){if (exp%2==1) result*=base;exp/=2;base*=base;}return result;}

ull fastpow(ull base, ull exp) {
    ull res = 1;
    while (exp) {
        if (exp & 1)
            res *= base;
        base *= base;
        res%=MOD;
        base%=MOD;
        exp >>= 1;
    }

    return res;
}

bool cmp(pair<pll,pll> i, pair<pll,pll> j){
    //if (i.first == j.second) return i.first < j.first;
    return i.first.second < j.first.second;
}
bool cmp2(pair<pll,pll> i, pair<pll,pll> j){
    //if (i.first == j.second) return i.first < j.first;
    return i.second.first < j.second.first;
}

ll l,r;
ll idx=1;
struct tree{

        vector<ll> seg;
        ll out = 0;

        void ini(ll n){
            while (idx < n) idx*=2;
            seg.resize(idx*4, out);
        }

        ll op(ll i, ll j){
            return i+j;
        }

        void build() { // Unused.
            for (int i = idx - 1;i > 0;i--) {
                seg[i] = op(seg[i * 2] , seg[i * 2 + 1]);
            }
        }

        void update(int i, ll x=1) { // 1 based i
            i += idx;
            i--; // Cause of this, remove for 0 based i
            seg[i] = x;
            while (i) {
                i /= 2;
                seg[i] = op(seg[i * 2], seg[i * 2 + 1]);
            }
        }

        // [inclusive, inclusive] and 1 based, just call calc(); when l and r are defined.
        ll calc(ll s = 1, ll e = idx, ll node = 1) {
            if (r < s || e < l)
                return out;
            if (l <= s and e <= r)
                return seg[node];
            ll mid = (s + e) / 2;
            return op(calc(s, mid, node * 2) , calc(mid + 1, e, node * 2 + 1));
        }
};

void solve() {
    //cout << fixed << setprecision(6);
    ll n; cin >> n; ll q; cin >> q;
    ll arr[n+2];
    for (int i=1;i<=n;i++) cin >> arr[i];
    pair<pll,pll> qs[q];
    for (int i=0;i<q;i++){
        cin >> qs[i].first.first >> qs[i].first.second;
        qs[i].second.first = i;
        qs[i].second.second=666;
    }
    sort(qs,qs+q,cmp);
    map<ll, deque<ll> > mp;
    tree s;
    s.ini(n);
    ll curi=0;
    for (auto& p : qs){
        while (curi < p.first.second){
            curi++;
            mp[arr[curi]].push_back(curi);
            //cout << curi;
            if (mp[arr[curi]].size() > 3) mp[arr[curi]].pop_front();
            if (mp[arr[curi]].size() == 3){
                s.update(mp[arr[curi]][0],-1);
                s.update(mp[arr[curi]][1],1);
                s.update(mp[arr[curi]][2],0);
            }
            else if (mp[arr[curi]].size() == 2){
                s.update(mp[arr[curi]][0],1);
                s.update(mp[arr[curi]][1],0);
            }
            else s.update(mp[arr[curi]][0],0);
        }
        l = p.first.first; r = p.first.second;
        p.second.second = s.calc();
    }
    sort(qs,qs+q,cmp2);
    for (auto& p : qs) cout << p.second.second << endl;
}



signed main() {
    ios::sync_with_stdio(false);cin.tie(nullptr);
    //freopen("auxiliary.in","r",stdin);
    //freopen("auxiliary.out","w",stdout);
    ll t=1;
    //cin >> t;
    for (int i=1; i<=t; i++){
        //cout << "Case " << i << ": \n";
        solve();
        cout << endl;
    }
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Incorrect 1 ms 348 KB Output isn't correct
3 Incorrect 1 ms 348 KB Output isn't correct
4 Incorrect 4 ms 860 KB Output isn't correct
5 Incorrect 90 ms 9020 KB Output isn't correct
6 Incorrect 92 ms 9224 KB Output isn't correct
7 Incorrect 240 ms 18260 KB Output isn't correct
8 Incorrect 395 ms 31388 KB Output isn't correct
9 Incorrect 491 ms 36040 KB Output isn't correct
10 Incorrect 609 ms 40560 KB Output isn't correct