This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//# 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 (stderr)
examination.cpp:4:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
# pragma GCC optimization ("unroll-loops")
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |