Cod sursa(job #3171195)

Utilizator LucasSecaraSecara Lucas Victor LucasSecara Data 18 noiembrie 2023 15:10:46
Problema Marbles Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.81 kb
#include <iostream>
#include <fstream>

using namespace std;

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

int v[2147483648], n, m, c, x, y;

void verifBile(int x, int y){
    int f[65]={0}, maxi=0;
    for (int i=x; i<=y; i++){
        if (v[i]!=0){
            f[v[i]]++;
            if (f[v[i]]>maxi){
                maxi = f[v[i]];
            }
        }
    }
    fout << maxi << '\n';
}

void mutareBile(int i, int j){
    if (j<i) swap(j, i);
    int aux = v[j];
    for (int k = i; k < j; k++){
        v[k+1] = v[k];
    }
    v[i] = aux;
}

int main() {
    fin >> n >> m;
    for (int i=1; i<=n; i++){
        fin >> x >> y;
        v[x]=y;
    }
    for (int i=1; i<=m; i++){
        fin >> c >> x >> y;
        if (c==0) mutareBile(x, x+y);
        else if (c==1) verifBile(x, y);
    }
    return 0;
}