Submission #246084

# Submission time Handle Problem Language Result Execution time Memory
246084 2020-07-08T07:10:04 Z Vimmer Poklon (COCI17_poklon) C++14
0 / 140
1470 ms 14812 KB
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("-O3")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("fast-math")
//#pragma GCC optimize("no-stack-protector")

#define F first
#define S second
#define sz(x) int(x.size())
#define pb push_back
#define pf push_front
#define N 100100
#define M ll(1e9 + 7)
#define inf 1e9 + 1e9

using namespace std;
//using namespace __gnu_pbds;

typedef long double ld;
typedef long long ll;
typedef short int si;
typedef array <int, 3> a3;

//typedef tree <int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

vector <a3> qr;

int kol[500005], a[500005], koler = 0;

bool cmp(a3 a, a3 b)
{
    int lx = a[0] / 700;

    int rx = b[0] / 700;

    if (lx != rx) return lx < rx;

    if (lx % 2) return a[1] > b[1];

    return a[1] < b[1];
}

void del(int x)
{
    kol[a[x]]--;

    if (kol[a[x]] == 1) koler--;

    if (kol[a[x]] == 2) koler++;
}

void add(int x)
{
    kol[a[x]]++;

    if (kol[a[x]] == 3) koler--;

    if (kol[a[x]] == 2) koler++;
}

int main()
{
    ////freopen("input.txt", "r", stdin); //freopen("output4.txt", "w", stdout);

    ios_base::sync_with_stdio(0); istream::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    int n, k;

    cin >> n >> k;

    vector <int> pr(n);

    for (int i = 0; i < n; i++) {cin >> a[i]; pr[i] = a[i];}

    sort(pr.begin(), pr.end());

    pr.resize(unique(pr.begin(), pr.end()) - pr.begin());

    for (int i = 0; i < n; i++) a[i] = lower_bound(pr.begin(), pr.end(), a[i]) - pr.begin();

    for (int i = 0; i < k; i++) {int x, y; cin >> x >> y; qr.pb({x, y, i});}

    sort(qr.begin(), qr.end(), cmp);

    int ans[n], L = 0, R = -1;

    for (int i = 0; i < k; i++)
    {
        int nm = qr[i][2], l = qr[i][0], r = qr[i][1];

        while (R < r) {R++; add(R);}

        while (L < l) {del(L); L++;}

        while (R > r) {del(R); R--;}

        while (L > l) {L--; add(L);}

        ans[nm] = koler;
    }

    for (int i = 0; i < k; i++) cout << ans[i] << '\n';
}
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 384 KB Output isn't correct
2 Incorrect 5 ms 384 KB Output isn't correct
3 Incorrect 7 ms 384 KB Output isn't correct
4 Incorrect 12 ms 640 KB Output isn't correct
5 Incorrect 172 ms 4460 KB Output isn't correct
6 Incorrect 175 ms 4460 KB Output isn't correct
7 Incorrect 411 ms 7528 KB Output isn't correct
8 Incorrect 702 ms 10724 KB Output isn't correct
9 Incorrect 1058 ms 12512 KB Output isn't correct
10 Incorrect 1470 ms 14812 KB Output isn't correct