Pagini recente » Cod sursa (job #1326384) | Cod sursa (job #2748067) | Cod sursa (job #443467) | Cod sursa (job #564728) | Cod sursa (job #2549503)
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;
class InParser {
private:
FILE *fin;
char *buff;
int sp;
char read_ch() {
++sp;
if (sp == 4096) {
sp = 0;
fread(buff, 1, 4096, fin);
}
return buff[sp];
}
public:
InParser(const char* nume) {
fin = fopen(nume, "r");
buff = new char[4096]();
sp = 4095;
}
InParser& operator >> (int &n) {
char c;
while (!isdigit(c = read_ch()) && c != '-');
int sgn = 1;
if (c == '-') {
n = 0;
sgn = -1;
} else {
n = c - '0';
}
while (isdigit(c = read_ch())) {
n = 10 * n + c - '0';
}
n *= sgn;
return *this;
}
InParser& operator >> (long long &n) {
char c;
n = 0;
while (!isdigit(c = read_ch()) && c != '-');
long long sgn = 1;
if (c == '-') {
n = 0;
sgn = -1;
} else {
n = c - '0';
}
while (isdigit(c = read_ch())) {
n = 10 * n + c - '0';
}
n *= sgn;
return *this;
}
};
ifstream cin("marbles.in");
ofstream cout("marbles.out");
vector<int> s[70];
int bound(int cul, int pz, int which){
int st = 0;
int dr = s[cul].size() - 1;
int bs = 0;
while(st <= dr){
int mij = (st + dr) / 2;
if(s[cul][mij] <= pz){
bs = mij;
st = mij + 1;
}
else dr = mij - 1;
}
if(!which){
if(s[cul][bs] < pz)
++bs;
}
return bs;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int n, m;
cin >> n >> m;
for(int i = 1; i <= n; ++i){
int x, cul;
cin >> x >> cul;
s[cul].push_back(x);
}
for(int i = 1; i <= 64; ++i)
sort(s[i].begin(), s[i].end());
for(int i = 1; i <= m; ++i){
int t, xi, xj;
cin >> t >> xi >> xj;
int lgMax = 0;
for(int cul = 1; cul <= 64; ++cul)
if(s[cul].size() > 0)
if(t == 0){
int pz = bound(cul, xi, 0);
if(s[cul][pz] == xi)
s[cul][pz] += xj;
}
else if(t == 1){
int st = bound(cul, xi, 0);
int fs = bound(cul, xj, 1);
lgMax = max(lgMax, fs - st + 1);
}
if(t)
cout << lgMax << '\n';
}
return 0;
}