//# pragma GCC optimize("Ofast,no-stack-protector")
//# pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
# pragma GCC optimize("Ofast")
# pragma GCC optimization ("unroll-loops")
# include "bits/stdc++.h"
std::pair<int,int> DR[] = {{-1,0},{0,1},{1,0},{0,-1},{-1,1},{-1,-1},{1,1},{1,-1}};
# define ll long long
# define clock (clock() * 1000.0 / CLOCKS_PER_SEC)
# define rc(s) return cout << s,0
# define rcg(s) cout << s;exit(0)
# define _ ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
# define db(x) cerr << #x << " = " << x << '\n'
# define pb push_back
# define mp make_pair
# define all(s) s.begin(),s.end()
# define sz(x) (int)((x).size())
//# define int ll
using namespace std;
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# define LOCAL
# define sim template < class c
# define ris return * this
# define dor > debug & operator <<
# define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
*this << "[";
for (auto it = d.b; it != d.e; ++it)
*this << ", " + 2 * (it == d.b) << *it;
ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define show(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
int gcd(int a, int b)
{
if(b) return gcd(b,a%b);
return a;
}mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
const int L = 1024;
int n,q,s[1 << 17],t[1 << 17],a[1 << 17],x[1 << 17],y[1 << 17],z[1 << 17],ans[1 << 17],valt[1 << 17];
vector<int>vec[1 << 17],qrys[1 << 17];
vector<pair<int,int>>vecs,vect;
inline void upd(int pos,int val)
{
int block = (n - pos) / L;
vec[block].insert(upper_bound(vec[block].begin(),vec[block].end(),val),val);
a[pos] = val;
}
inline int qry(int idx,int val)
{
int ans = 0,block = 0,l = n - L + 1;
for(;l >= idx;l -= L,block++) ans += vec[block].end() - lower_bound(vec[block].begin(),vec[block].end(),val);
l += L;
while(l != idx) ans += (a[--l] >= val);
return ans;
}
int32_t main(){_
//freopen("input","r",stdin);
cin >> n >> q;
for(int i = 1;i <= n;i++)
{
cin >> s[i] >> t[i];
a[i] = -1;
vecs.pb(mp(s[i],i));
vect.pb(mp(t[i],i));
}
vecs.pb(mp(-1,0));
sort(vecs.begin(),vecs.end());
sort(vect.begin(),vect.end());
for(int i = 0;i < sz(vect);i++) valt[vect[i].second] = i + 1;
for(int i = 1;i <= q;i++)
{
cin >> x[i] >> y[i] >> z[i];
int IT = lower_bound(vecs.begin(),vecs.end(),mp(x[i],-1)) - vecs.begin() - 1;
auto it = lower_bound(vect.begin(),vect.end(),mp(y[i],-1));
if(it != vect.end()) y[i] = valt[(*it).second], qrys[IT].pb(i);
}
for(int i = sz(vecs) - 1;i >= 0;i--)
{
for(auto it : qrys[i]) ans[it] = qry(y[it],z[it]);
//debug() << show(qrys[i]);
if(i) upd(valt[vecs[i].second],s[vecs[i].second] + t[vecs[i].second]);
}
for(int i = 1;i <= q;i++) cout << ans[i] << '\n';
return 0;
}
Compilation message
examination.cpp:4:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
# pragma GCC optimization ("unroll-loops")
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
6520 KB |
Output is correct |
2 |
Correct |
8 ms |
6520 KB |
Output is correct |
3 |
Correct |
8 ms |
6520 KB |
Output is correct |
4 |
Correct |
8 ms |
6492 KB |
Output is correct |
5 |
Correct |
8 ms |
6520 KB |
Output is correct |
6 |
Correct |
8 ms |
6520 KB |
Output is correct |
7 |
Correct |
13 ms |
6776 KB |
Output is correct |
8 |
Correct |
13 ms |
6776 KB |
Output is correct |
9 |
Correct |
13 ms |
6776 KB |
Output is correct |
10 |
Correct |
12 ms |
6780 KB |
Output is correct |
11 |
Correct |
12 ms |
6776 KB |
Output is correct |
12 |
Correct |
12 ms |
6776 KB |
Output is correct |
13 |
Correct |
13 ms |
6776 KB |
Output is correct |
14 |
Correct |
13 ms |
6776 KB |
Output is correct |
15 |
Correct |
13 ms |
6776 KB |
Output is correct |
16 |
Correct |
12 ms |
6776 KB |
Output is correct |
17 |
Correct |
12 ms |
6776 KB |
Output is correct |
18 |
Correct |
10 ms |
6776 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
259 ms |
13764 KB |
Output is correct |
2 |
Correct |
302 ms |
13836 KB |
Output is correct |
3 |
Correct |
261 ms |
13792 KB |
Output is correct |
4 |
Correct |
246 ms |
13840 KB |
Output is correct |
5 |
Correct |
203 ms |
12716 KB |
Output is correct |
6 |
Correct |
178 ms |
12768 KB |
Output is correct |
7 |
Correct |
236 ms |
13060 KB |
Output is correct |
8 |
Correct |
301 ms |
13796 KB |
Output is correct |
9 |
Correct |
277 ms |
13024 KB |
Output is correct |
10 |
Correct |
190 ms |
12432 KB |
Output is correct |
11 |
Correct |
198 ms |
13156 KB |
Output is correct |
12 |
Correct |
96 ms |
12000 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
259 ms |
13764 KB |
Output is correct |
2 |
Correct |
302 ms |
13836 KB |
Output is correct |
3 |
Correct |
261 ms |
13792 KB |
Output is correct |
4 |
Correct |
246 ms |
13840 KB |
Output is correct |
5 |
Correct |
203 ms |
12716 KB |
Output is correct |
6 |
Correct |
178 ms |
12768 KB |
Output is correct |
7 |
Correct |
236 ms |
13060 KB |
Output is correct |
8 |
Correct |
301 ms |
13796 KB |
Output is correct |
9 |
Correct |
277 ms |
13024 KB |
Output is correct |
10 |
Correct |
190 ms |
12432 KB |
Output is correct |
11 |
Correct |
198 ms |
13156 KB |
Output is correct |
12 |
Correct |
96 ms |
12000 KB |
Output is correct |
13 |
Correct |
367 ms |
13784 KB |
Output is correct |
14 |
Correct |
291 ms |
14528 KB |
Output is correct |
15 |
Correct |
269 ms |
14564 KB |
Output is correct |
16 |
Correct |
392 ms |
14560 KB |
Output is correct |
17 |
Correct |
227 ms |
13540 KB |
Output is correct |
18 |
Correct |
190 ms |
13640 KB |
Output is correct |
19 |
Correct |
368 ms |
14532 KB |
Output is correct |
20 |
Correct |
347 ms |
14564 KB |
Output is correct |
21 |
Correct |
533 ms |
14152 KB |
Output is correct |
22 |
Correct |
183 ms |
13408 KB |
Output is correct |
23 |
Correct |
224 ms |
14060 KB |
Output is correct |
24 |
Correct |
96 ms |
12768 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
6520 KB |
Output is correct |
2 |
Correct |
8 ms |
6520 KB |
Output is correct |
3 |
Correct |
8 ms |
6520 KB |
Output is correct |
4 |
Correct |
8 ms |
6492 KB |
Output is correct |
5 |
Correct |
8 ms |
6520 KB |
Output is correct |
6 |
Correct |
8 ms |
6520 KB |
Output is correct |
7 |
Correct |
13 ms |
6776 KB |
Output is correct |
8 |
Correct |
13 ms |
6776 KB |
Output is correct |
9 |
Correct |
13 ms |
6776 KB |
Output is correct |
10 |
Correct |
12 ms |
6780 KB |
Output is correct |
11 |
Correct |
12 ms |
6776 KB |
Output is correct |
12 |
Correct |
12 ms |
6776 KB |
Output is correct |
13 |
Correct |
13 ms |
6776 KB |
Output is correct |
14 |
Correct |
13 ms |
6776 KB |
Output is correct |
15 |
Correct |
13 ms |
6776 KB |
Output is correct |
16 |
Correct |
12 ms |
6776 KB |
Output is correct |
17 |
Correct |
12 ms |
6776 KB |
Output is correct |
18 |
Correct |
10 ms |
6776 KB |
Output is correct |
19 |
Correct |
259 ms |
13764 KB |
Output is correct |
20 |
Correct |
302 ms |
13836 KB |
Output is correct |
21 |
Correct |
261 ms |
13792 KB |
Output is correct |
22 |
Correct |
246 ms |
13840 KB |
Output is correct |
23 |
Correct |
203 ms |
12716 KB |
Output is correct |
24 |
Correct |
178 ms |
12768 KB |
Output is correct |
25 |
Correct |
236 ms |
13060 KB |
Output is correct |
26 |
Correct |
301 ms |
13796 KB |
Output is correct |
27 |
Correct |
277 ms |
13024 KB |
Output is correct |
28 |
Correct |
190 ms |
12432 KB |
Output is correct |
29 |
Correct |
198 ms |
13156 KB |
Output is correct |
30 |
Correct |
96 ms |
12000 KB |
Output is correct |
31 |
Correct |
367 ms |
13784 KB |
Output is correct |
32 |
Correct |
291 ms |
14528 KB |
Output is correct |
33 |
Correct |
269 ms |
14564 KB |
Output is correct |
34 |
Correct |
392 ms |
14560 KB |
Output is correct |
35 |
Correct |
227 ms |
13540 KB |
Output is correct |
36 |
Correct |
190 ms |
13640 KB |
Output is correct |
37 |
Correct |
368 ms |
14532 KB |
Output is correct |
38 |
Correct |
347 ms |
14564 KB |
Output is correct |
39 |
Correct |
533 ms |
14152 KB |
Output is correct |
40 |
Correct |
183 ms |
13408 KB |
Output is correct |
41 |
Correct |
224 ms |
14060 KB |
Output is correct |
42 |
Correct |
96 ms |
12768 KB |
Output is correct |
43 |
Correct |
393 ms |
14640 KB |
Output is correct |
44 |
Correct |
387 ms |
14636 KB |
Output is correct |
45 |
Correct |
307 ms |
14700 KB |
Output is correct |
46 |
Correct |
395 ms |
14692 KB |
Output is correct |
47 |
Correct |
240 ms |
13640 KB |
Output is correct |
48 |
Correct |
236 ms |
13408 KB |
Output is correct |
49 |
Correct |
367 ms |
13868 KB |
Output is correct |
50 |
Correct |
528 ms |
14688 KB |
Output is correct |
51 |
Correct |
609 ms |
13808 KB |
Output is correct |
52 |
Correct |
207 ms |
13412 KB |
Output is correct |
53 |
Correct |
205 ms |
14052 KB |
Output is correct |