Cod sursa(job #1744934)

Utilizator fanache99Constantin-Buliga Stefan fanache99 Data 20 august 2016 18:59:09
Problema Marbles Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.55 kb
#include <fstream>
#include <algorithm>

using namespace std;

ifstream cin("marbles.in");
ofstream cout("marbles.out");

const int MAXN = 100010;
const int MAXC = 67;

int sum[MAXN][MAXC];
pair<int, int> v[MAXN];
int n, m;

int BinarySearch(int x) {
    int left = 1, right = n;
    while (left <= right) {
        int middle = (left + right) / 2;
        if (v[middle].first >= x)
            right = middle - 1;
        else
            left = middle + 1;
    }
    return left;
}

int OtherBinarySearch(int x) {
    int left = 1, right = n;
    while (left <= right) {
        int middle = (left + right) / 2;
        if (v[middle].first > x)
            right = middle - 1;
        else
            left = middle + 1;
    }
    return right;
}

int main() {
    cin >> n >> m;
    for (int i = 1; i <= n; i++)
        cin >> 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++) {
            sum[i][j] = sum[i - 1][j];
            if (v[i].second == j)
                sum[i][j]++;
        }
    for (int i = 1; i <= m; i++) {
        int type, x, y;
        cin >> type >> x >> y;
        if (type == 0)
            v[BinarySearch(x)].first += y;
        else {
            int answer = 0;
            int left = BinarySearch(x), right = OtherBinarySearch(y);
            for (int c = 1; c <= 64; c++)
                answer = max(answer, sum[right][c] - sum[left - 1][c]);
            cout << answer << "\n";
        }
    }
    return 0;
}