Cod sursa(job #2961308)

Utilizator bem.andreiIceman bem.andrei Data 6 ianuarie 2023 09:22:35
Problema Marbles Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.17 kb
#include <bits/stdc++.h>

using namespace std;
ifstream r("marbles.in");
ofstream w("marbles.out");

struct bila
{
    int x;
    short int c;
} v[1<<17];
int a[1<<17][65],n,m;

int bs(int x, bool tip)
{
    int pos, step=1<<16;
    for (pos=0; step; step>>=1)
    {
        if (pos+step<=n && v[pos+step].x<x+tip)
        {
            pos+=step;
        }
    }
    return pos;
}

bool cmp(bila a,bila b)
{
    return a.x<b.x;
}

int main()
{
    r>>n>>m;
    for (int i=1; i<=n; i++)
    {
        r>>v[i].x>>v[i].c;
    }
    sort(v+1,v+n+1,cmp);
    for (int i=1; i<=n; i++)
    {
        for (int j=1; j<=64; j++)
        {
            a[i][j]=a[i-1][j];
        }
        a[i][v[i].c]++;
    }
    for (int i=1; i<=m; i++)
    {
        int q, x, y;
        r>>q>>x>>y;
        if (q==0)
        {
            v[bs(x,1)].x+=y;
            continue;
        }
        x=bs(x,0);
        y=bs(y,1);
        q=a[y][1]-a[x][1];
        for (int j=2; j<=64; j++)
        {
            if (q<a[y][j]-a[x][j])
            {
                q=a[y][j]-a[x][j];
            }
        }
        w<<q<<"\n";
    }
    return 0;
}