Cod sursa(job #3135240)

Utilizator profinfo114Prof Info profinfo114 Data 2 iunie 2023 14:02:41
Problema Marbles Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.17 kb
#include <fstream>
#include <algorithm>

using namespace std;

ifstream fin("marbles.in");
ofstream fout("marbles.out");

int n, m, c, x, y, dp[100005][70];
pair<int, int> v[100005];
int cb(int x) {
    int i = 0, pas = (1 << 16);
    while(pas > 0) {
        if(i + pas <= n && v[i + pas].first < x) {
            i += pas;
        }
        pas >>= 1;
    }
    return i + 1;
}

int main() {
    fin >> n >> m;
    for(int i = 1; i <= n; i++) {
        fin >> v[i].first >> v[i].second;
    }
    sort(v + 1, v + n + 1);
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= 64; j++) {
            dp[i][j] = dp[i - 1][j];
        }
        dp[i][v[i].second]++;
    }
    for(int i = 1; i <= m; i++) {
        fin >> c >> x >> y;
        if(c == 0) {
            int p = cb(x);
            v[p].first += y;
        } else {
            int ii = cb(x), jj = cb(y);
            if(v[jj].first > y) {
                jj--;
            }
            int ans = 0;
            for(int j = 1; j <= 64; j++) {
                ans = max(ans, dp[jj][j] - dp[ii - 1][j]);
            }
            fout << ans << "\n";
        }
    }
    return 0;
}