Pagini recente » Cod sursa (job #2801781) | Cod sursa (job #1354451) | Cod sursa (job #1608240) | Cod sursa (job #1979950) | Cod sursa (job #3340818)
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
ifstream fin("marbles.in");
ofstream fout("marbles.out");
typedef __gnu_pbds::tree<int, __gnu_pbds::null_type,less<int>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>idset;
map<int,int>m;
int main() {
std::ios::sync_with_stdio(false);
fin.tie(nullptr);
fout.tie(nullptr);
int n,q,x,y,z;
fin>>n>>q;
vector<idset>s;
s.resize(65);
for (int i=1;i<=n;i++) {
fin>>x>>y;
m[x]=y;
s[y].insert(x);
}
for (int i=1;i<=q;i++) {
fin>>x>>y>>z;
if (x==0) {
int cul=m[y];
m[y]=0;
m[y+z]=cul;
s[cul].erase(y);
s[cul].insert(y+z);
}else {
x=y;
y=z;
int mv=0;
for (int j=1;j<=64;j++) {
if ((int)s[j].size()<=mv) continue;
auto st=s[j].lower_bound(x),dr=s[j].upper_bound(y);
if (st!=s[j].end()&&st!=dr) {
dr=prev(dr);
int cnt=s[j].order_of_key(*dr)-s[j].order_of_key(*st)+1;
mv=max(mv,cnt);
}
}
fout<<mv<<'\n';
}
}
return 0;
}