Cod sursa(job #3200097)

Utilizator Mihai_OctMihai Octavian Mihai_Oct Data 3 februarie 2024 15:10:43
Problema Marbles Scor 90
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.16 kb
#include <bits/stdc++.h>

using namespace std;

ifstream fin("marbles.in");
ofstream fout("marbles.out");
const int Max = (1 << 17);
struct bila {
    int p, c;
} q[Max + 2];
int n, m, i, r, v[Max + 2];
int a[Max + 2][66];

static inline bool Cmp(bila a, bila b) {
    return (a.p < b.p);
}

int main() {
    fin >> n >> m;
    for(i = 1; i <= n; i++) fin >> q[i].p >> q[i].c;
    sort(q + 1, q + n + 1, Cmp);
    for(i = 1; i <= n; i++) {
        v[i] = q[i].p;
        a[i][q[i].c] = 1;
    }


    for(i = 1; i <= n; i++) {
        for(int j = 1; j <= 64; j++) a[i][j] += a[i - 1][j];
    }

    for(i = 1; i <= m; i++) {
        int op, x, y;
        fin >> op >> x >> y;
        if(op == 0) {
            /// pe scurt: pozitia la care intalnesc pe x creste cu y
            *lower_bound(v + 1, v + n + 1, x) += y;
        }
        else {
            x = (lower_bound(v + 1, v + n + 1, x) - v);
            y = (lower_bound(v + 1, v + n + 1, y) - v) - 1; /// pt ca upper bound
            r = 0;
            for(int i = 1; i <= 64; i++) r = max(r, a[y][i] - a[x - 1][i]);
            fout << r << "\n";
        }
    }

    return 0;
}