#include <bits/stdc++.h>
using namespace std;
#define int long long
#define form2(i, a, b) for (int i = (a); i < (b); ++i)
#define ford2(i, a, b) for (int i = (a-1); i >= b; --i)
#define form(i, n) form2(i, 0, n)
#define ford(i, n) ford2(i, n, 0)
#define chmax(x, v) x = max(x, (v))
#define chmin(x, v) x = min(x, (v))
#define fi first
#define se second
const long long BIG = 1000000000000000000LL;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
void cpr(string s, vector<int> v)
{ int i = 0; for (char c : s) { if (c == '$') cout << v[i++]; else cout << c; } cout << '\n'; }
void cpr(string s) { cpr(s, {}); }
void solve();
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);
solve();
return 0;
}
const int borne2 = (1LL << 40LL);
struct Node
{
int val;
pii itv;
Node *lc=nullptr, *rc=nullptr;
void init()
{
val=0;
itv = {0, borne2-1};
lc=nullptr;
rc=nullptr;
}
Node* left()
{
if (lc == nullptr) {
lc = new Node();
lc->val = 0;
lc->itv = {itv.fi, (itv.fi+itv.se)/2LL};
}
return lc;
}
Node* right()
{
if (rc == nullptr) {
rc = new Node();
rc->val = 0;
rc->itv = {(itv.fi+itv.se)/2LL + 1LL, itv.se};
}
return rc;
}
int requete(int a, int b)
{
if (itv.fi > b || itv.se < a) return 0;
if (a <= itv.fi && itv.se <= b) return val;
return left()->requete(a,b) + right()->requete(a,b);
}
void incr(int x)
{
if (itv.fi > x || itv.se < x) return;
if (itv.fi == x && itv.se == x) { ++val; return; }
left()->incr(x);
right()->incr(x);
val = left()->val + right()->val;
}
};
struct Requete
{
int maths=0, info=0, rqAdd=0, tot=0, rep=0, ind=0;
};
bool cmpAdd(Requete a, Requete b)
{
return tie(a.rqAdd, a.ind) < tie(b.rqAdd, b.ind);
}
bool cmpMaths(Requete a, Requete b)
{
return tie(a.maths, a.ind) < tie(b.maths, b.ind);
}
bool cmpInd(Requete a, Requete b)
{
return a.ind < b.ind;
}
const int borne = 4 * ((int)(1e5) + 5);
pii etud[borne];
Requete req[borne];
int nbEtud, nbReq;
Node* sc;
Node* oth;
void bourrin()
{
form(i, nbEtud) cin >> etud[i].fi >> etud[i].se;
form(iReq, nbReq) {
int crMaths, crInfo, crTot;
cin >> crMaths >> crInfo >> crTot;
int rep = 0;
form(indEtud, nbEtud) {
auto &ed = etud[indEtud];
if (ed.fi >= crMaths && ed.se >= crInfo && ed.fi + ed.se >= crTot) {
++rep;
}
}
cout << rep << "\n";
}
}
void solve()
{
cin >> nbEtud >> nbReq;
if (nbEtud <= 3000 && nbReq <= 3000) { bourrin(); return; }
form(i, nbEtud) cin >> etud[i].fi >> etud[i].se;
sort(etud, etud+nbEtud);
form(i, nbReq) {
cin >> req[i].maths >> req[i].info >> req[i].tot;
req[i].rqAdd = req[i].tot - req[i].info;
req[i].ind = i;
}
sort(req, req+nbReq, cmpAdd);
vector<int> tmp(borne, 0);
sc = new Node();
oth = new Node();
sc->init();
oth->init();
int iAdd = nbEtud-1;
ford(iReq, nbReq) {
auto &cur = req[iReq];
while (iAdd >= 0 && etud[iAdd].fi >= cur.rqAdd) {
int ol = etud[iAdd].se;
sc->incr(ol);
int ol2 = etud[iAdd].se + etud[iAdd].fi;
oth->incr(ol2);
--iAdd;
}
cur.rep = sc->requete(cur.info, borne2-1);
int lim = cur.tot;
chmin(lim, borne2-1);
chmax(lim, 0LL);
cur.rep -= oth->requete(lim, borne2-1);
}
sc = new Node();
oth = new Node();
sc->init();
oth->init();
sort(req, req+nbReq, cmpMaths);
iAdd=nbEtud-1;
ford(iReq, nbReq) {
auto &cur = req[iReq];
while (iAdd >= 0 && etud[iAdd].fi >= cur.maths) {
int ol = etud[iAdd].se;
sc->incr(ol);
int ol2 = etud[iAdd].se + etud[iAdd].fi;
oth->incr(ol2);
--iAdd;
}
if (cur.maths + cur.info >= cur.tot) {
cur.rep = sc->requete(cur.info, borne2-1);
continue;
}
int lim = cur.tot;
chmin(lim, borne2-1);
chmax(lim, 0LL);
cur.rep += oth->requete(lim, borne2-1);
}
sort(req, req+nbReq, cmpInd);
form(iReq, nbReq) {
cout << req[iReq].rep << "\n";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
432 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
44 ms |
384 KB |
Output is correct |
8 |
Correct |
47 ms |
384 KB |
Output is correct |
9 |
Correct |
45 ms |
384 KB |
Output is correct |
10 |
Correct |
44 ms |
384 KB |
Output is correct |
11 |
Correct |
44 ms |
384 KB |
Output is correct |
12 |
Correct |
45 ms |
504 KB |
Output is correct |
13 |
Correct |
46 ms |
384 KB |
Output is correct |
14 |
Correct |
48 ms |
384 KB |
Output is correct |
15 |
Correct |
46 ms |
384 KB |
Output is correct |
16 |
Correct |
27 ms |
384 KB |
Output is correct |
17 |
Correct |
35 ms |
384 KB |
Output is correct |
18 |
Correct |
16 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
761 ms |
55228 KB |
Output is correct |
2 |
Correct |
716 ms |
55224 KB |
Output is correct |
3 |
Correct |
732 ms |
55236 KB |
Output is correct |
4 |
Correct |
294 ms |
27900 KB |
Output is correct |
5 |
Correct |
479 ms |
46240 KB |
Output is correct |
6 |
Correct |
271 ms |
10584 KB |
Output is correct |
7 |
Correct |
763 ms |
55160 KB |
Output is correct |
8 |
Correct |
685 ms |
54264 KB |
Output is correct |
9 |
Correct |
766 ms |
54336 KB |
Output is correct |
10 |
Correct |
422 ms |
45932 KB |
Output is correct |
11 |
Correct |
287 ms |
27676 KB |
Output is correct |
12 |
Correct |
252 ms |
9976 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
761 ms |
55228 KB |
Output is correct |
2 |
Correct |
716 ms |
55224 KB |
Output is correct |
3 |
Correct |
732 ms |
55236 KB |
Output is correct |
4 |
Correct |
294 ms |
27900 KB |
Output is correct |
5 |
Correct |
479 ms |
46240 KB |
Output is correct |
6 |
Correct |
271 ms |
10584 KB |
Output is correct |
7 |
Correct |
763 ms |
55160 KB |
Output is correct |
8 |
Correct |
685 ms |
54264 KB |
Output is correct |
9 |
Correct |
766 ms |
54336 KB |
Output is correct |
10 |
Correct |
422 ms |
45932 KB |
Output is correct |
11 |
Correct |
287 ms |
27676 KB |
Output is correct |
12 |
Correct |
252 ms |
9976 KB |
Output is correct |
13 |
Correct |
919 ms |
59384 KB |
Output is correct |
14 |
Correct |
903 ms |
57464 KB |
Output is correct |
15 |
Correct |
809 ms |
55100 KB |
Output is correct |
16 |
Correct |
406 ms |
28536 KB |
Output is correct |
17 |
Correct |
727 ms |
46668 KB |
Output is correct |
18 |
Correct |
284 ms |
10488 KB |
Output is correct |
19 |
Correct |
949 ms |
59256 KB |
Output is correct |
20 |
Correct |
1080 ms |
57548 KB |
Output is correct |
21 |
Correct |
1006 ms |
59384 KB |
Output is correct |
22 |
Correct |
429 ms |
46192 KB |
Output is correct |
23 |
Correct |
343 ms |
27748 KB |
Output is correct |
24 |
Correct |
235 ms |
9952 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
432 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
44 ms |
384 KB |
Output is correct |
8 |
Correct |
47 ms |
384 KB |
Output is correct |
9 |
Correct |
45 ms |
384 KB |
Output is correct |
10 |
Correct |
44 ms |
384 KB |
Output is correct |
11 |
Correct |
44 ms |
384 KB |
Output is correct |
12 |
Correct |
45 ms |
504 KB |
Output is correct |
13 |
Correct |
46 ms |
384 KB |
Output is correct |
14 |
Correct |
48 ms |
384 KB |
Output is correct |
15 |
Correct |
46 ms |
384 KB |
Output is correct |
16 |
Correct |
27 ms |
384 KB |
Output is correct |
17 |
Correct |
35 ms |
384 KB |
Output is correct |
18 |
Correct |
16 ms |
384 KB |
Output is correct |
19 |
Correct |
761 ms |
55228 KB |
Output is correct |
20 |
Correct |
716 ms |
55224 KB |
Output is correct |
21 |
Correct |
732 ms |
55236 KB |
Output is correct |
22 |
Correct |
294 ms |
27900 KB |
Output is correct |
23 |
Correct |
479 ms |
46240 KB |
Output is correct |
24 |
Correct |
271 ms |
10584 KB |
Output is correct |
25 |
Correct |
763 ms |
55160 KB |
Output is correct |
26 |
Correct |
685 ms |
54264 KB |
Output is correct |
27 |
Correct |
766 ms |
54336 KB |
Output is correct |
28 |
Correct |
422 ms |
45932 KB |
Output is correct |
29 |
Correct |
287 ms |
27676 KB |
Output is correct |
30 |
Correct |
252 ms |
9976 KB |
Output is correct |
31 |
Correct |
919 ms |
59384 KB |
Output is correct |
32 |
Correct |
903 ms |
57464 KB |
Output is correct |
33 |
Correct |
809 ms |
55100 KB |
Output is correct |
34 |
Correct |
406 ms |
28536 KB |
Output is correct |
35 |
Correct |
727 ms |
46668 KB |
Output is correct |
36 |
Correct |
284 ms |
10488 KB |
Output is correct |
37 |
Correct |
949 ms |
59256 KB |
Output is correct |
38 |
Correct |
1080 ms |
57548 KB |
Output is correct |
39 |
Correct |
1006 ms |
59384 KB |
Output is correct |
40 |
Correct |
429 ms |
46192 KB |
Output is correct |
41 |
Correct |
343 ms |
27748 KB |
Output is correct |
42 |
Correct |
235 ms |
9952 KB |
Output is correct |
43 |
Correct |
2754 ms |
838164 KB |
Output is correct |
44 |
Correct |
2731 ms |
838700 KB |
Output is correct |
45 |
Correct |
2753 ms |
829664 KB |
Output is correct |
46 |
Correct |
1175 ms |
410236 KB |
Output is correct |
47 |
Correct |
2315 ms |
808952 KB |
Output is correct |
48 |
Correct |
287 ms |
10696 KB |
Output is correct |
49 |
Correct |
2873 ms |
831920 KB |
Output is correct |
50 |
Correct |
2841 ms |
821112 KB |
Output is correct |
51 |
Correct |
2688 ms |
815992 KB |
Output is correct |
52 |
Correct |
2252 ms |
809036 KB |
Output is correct |
53 |
Correct |
688 ms |
262492 KB |
Output is correct |