# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
750513 | 2023-05-29T15:19:08 Z | mars4 | Examination (JOI19_examination) | C++17 | 1443 ms | 17628 KB |
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; #define ff first #define ss second #define ll int64_t #define ld long double #define nl cout<<"\n" #define i128 __int128_t #define all(v) v.begin(),v.end() #define mset(a,v) memset((a),(v),sizeof(a)) #define forn(i,a,b) for(int64_t i=int64_t(a);i<int64_t(b);++i) #define forb(i,a,b) for(int64_t i=int64_t(a);i>=int64_t(b);--i) #define fastio() ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); #define mod 1'000'000'007 #define mod2 998'244'353 #define inf 1'000'000'000'000'007 #define pi 3.14159265358979323846 template<class key,class cmp=std::less<key>> using ordered_set=tree<key,null_type,cmp,rb_tree_tag,tree_order_statistics_node_update>; template<class L,class R> ostream& operator<<(ostream& out,pair<L,R> &p) {return out<<"("<<p.ff<<", "<<p.ss<<")";} template<class T> ostream& operator<<(ostream& out,vector<T> &v) {out<<"[";for(auto it=v.begin();it!=v.end();++it){if(it!=v.begin())out<<", ";out<<*it;}return out<<"]";} template<class T> ostream& operator<<(ostream& out,deque<T> &v) {out<<"[";for(auto it=v.begin();it!=v.end();++it){if(it!=v.begin())out<<", ";out<<*it;}return out<<"]";} template<class T> ostream& operator<<(ostream& out,set<T> &s) {out<<"{";for(auto it=s.begin();it!=s.end();++it){if(it!=s.begin())out<<", ";out<<*it;}return out<<"}";} template<class T> ostream& operator<<(ostream& out,ordered_set<T> &s) {out<<"{";for(auto it=s.begin();it!=s.end();++it){if(it!=s.begin())out<<", ";out<<*it;}return out<<"}";} template<class L,class R> ostream& operator<<(ostream& out,map<L,R> &m) {out<<"{";for(auto it=m.begin();it!=m.end();++it){if(it!=m.begin())out<<", ";out<<*it;}return out<<"}";} void dbg_out() {cerr<<"]\n";} template<typename Head,typename... Tail> void dbg_out(Head H,Tail... T) {cerr<<H;if(sizeof...(Tail))cerr<<", ";dbg_out(T...);} #ifdef LOCAL #define dbg(...) cerr<<"["<<#__VA_ARGS__<<"] = [",dbg_out(__VA_ARGS__) #else #define dbg(...) #endif //---------------------------------mars4--------------------------------- class Fentree { ll logN; ll sum(ll i) { ll res=0; for(;i;i-=i&(-i)) res+=fentree[i]; return res; } public: ll N; vector<ll> fentree; void init(ll n) { N=n; logN=65-__builtin_clzll(n); fentree=vector<ll>(N+1); } void build(vector<ll> &a) { for(ll i=1;i<=N;i++) { fentree[i]+=a[i-1]; if(i+(i&-i)<=N) fentree[i+(i&-i)]+=fentree[i]; } } void update(ll i,ll val) { for(i++;i<=N;i+=i&(-i)) fentree[i]+=val; } ll sum(ll l,ll r) { if(l>r) { return 0; } return sum(r+1)-sum(l); } ll kth_element(ll k) { ll val=0; ll pos=0; for(ll i=logN;i>=0;i--) { ll r=1ll<<i; if(pos+r<=N and val+fentree[pos+r]<k) { val+=fentree[pos+r]; pos+=r; } } return pos; } }; const ll B=320; vector<pair<ll,ll>> a; vector<pair<ll,ll>> b; vector<ll> c; vector<ll> cnt; Fentree f; struct query { ll l,r,tot,id; bool operator < (const query &o) const { if(l/B==o.l/B) { if((l/B)%2==0) return r<o.r; else return r>o.r; } else return l<o.l; } }; class Mo { ll L=-1; ll R=-1; void updateL(ll i) { ll ind=a[i].ss; cnt[ind]++; if(cnt[ind]==2) { f.update(c[ind],1); } } void removeL(ll i) { ll ind=a[i].ss; if(cnt[ind]==2) { f.update(c[ind],-1); } cnt[ind]--; } void updateR(ll i) { ll ind=b[i].ss; cnt[ind]++; if(cnt[ind]==2) { f.update(c[ind],1); } } void removeR(ll i) { ll ind=b[i].ss; if(cnt[ind]==2) { f.update(c[ind],-1); } cnt[ind]--; } public: ll query(query q) { ll l=q.l; ll r=q.r; while(L<l) { L++; updateL(L); } while(R<r) { R++; updateR(R); } while(L>l) { removeL(L); L--; } while(R>r) { removeR(R); R--; } return f.sum(q.tot,f.N-1); } }; int main() { fastio(); ll z,n,m,t,k,i,j,l,d,h,r; cin>>n>>m; a=vector<pair<ll,ll>>(n); b=vector<pair<ll,ll>>(n); c=vector<ll>(n); cnt=vector<ll>(n); f.init(n); vector<ll> va; vector<ll> vb; vector<ll> vc; forn(i,0,n) { cin>>a[i].ff>>b[i].ff; c[i]=a[i].ff+b[i].ff; a[i].ss=i; b[i].ss=i; va.push_back(a[i].ff); vb.push_back(b[i].ff); vc.push_back(c[i]); } sort(all(va),greater<ll>()); sort(all(vb),greater<ll>()); sort(all(vc)); forn(i,0,n) { a[i].ff=lower_bound(all(va),a[i].ff,greater<ll>())-va.begin(); b[i].ff=lower_bound(all(vb),b[i].ff,greater<ll>())-vb.begin(); c[i]=lower_bound(all(vc),c[i])-vc.begin(); } sort(all(a)); sort(all(b)); vector<query> q(m); vector<ll> ans(m); forn(i,0,m) { auto &[l,r,tot,id]=q[i]; cin>>l>>r>>tot; l=upper_bound(all(va),l,greater<ll>())-va.begin()-1; r=upper_bound(all(vb),r,greater<ll>())-vb.begin()-1; tot=lower_bound(all(vc),tot)-vc.begin(); id=i; } sort(all(q)); Mo mo; for(auto qu:q) { ans[qu.id]=mo.query(qu); } for(ll i:ans) { cout<<i<<"\n"; } cerr<<"\nTime elapsed: "<<1000*clock()/CLOCKS_PER_SEC<<"ms\n"; return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 212 KB | Output is correct |
3 | Correct | 1 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 212 KB | Output is correct |
5 | Correct | 1 ms | 212 KB | Output is correct |
6 | Correct | 1 ms | 212 KB | Output is correct |
7 | Correct | 14 ms | 608 KB | Output is correct |
8 | Correct | 9 ms | 724 KB | Output is correct |
9 | Correct | 10 ms | 724 KB | Output is correct |
10 | Correct | 9 ms | 632 KB | Output is correct |
11 | Correct | 6 ms | 596 KB | Output is correct |
12 | Correct | 7 ms | 724 KB | Output is correct |
13 | Correct | 14 ms | 832 KB | Output is correct |
14 | Correct | 9 ms | 744 KB | Output is correct |
15 | Correct | 10 ms | 852 KB | Output is correct |
16 | Correct | 4 ms | 712 KB | Output is correct |
17 | Correct | 7 ms | 752 KB | Output is correct |
18 | Correct | 4 ms | 716 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1304 ms | 12728 KB | Output is correct |
2 | Correct | 1443 ms | 12732 KB | Output is correct |
3 | Correct | 1442 ms | 12728 KB | Output is correct |
4 | Correct | 998 ms | 12732 KB | Output is correct |
5 | Correct | 212 ms | 12728 KB | Output is correct |
6 | Correct | 159 ms | 12732 KB | Output is correct |
7 | Correct | 540 ms | 15140 KB | Output is correct |
8 | Correct | 656 ms | 15136 KB | Output is correct |
9 | Correct | 585 ms | 15052 KB | Output is correct |
10 | Correct | 206 ms | 14292 KB | Output is correct |
11 | Correct | 1146 ms | 14340 KB | Output is correct |
12 | Correct | 95 ms | 13404 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1304 ms | 12728 KB | Output is correct |
2 | Correct | 1443 ms | 12732 KB | Output is correct |
3 | Correct | 1442 ms | 12728 KB | Output is correct |
4 | Correct | 998 ms | 12732 KB | Output is correct |
5 | Correct | 212 ms | 12728 KB | Output is correct |
6 | Correct | 159 ms | 12732 KB | Output is correct |
7 | Correct | 540 ms | 15140 KB | Output is correct |
8 | Correct | 656 ms | 15136 KB | Output is correct |
9 | Correct | 585 ms | 15052 KB | Output is correct |
10 | Correct | 206 ms | 14292 KB | Output is correct |
11 | Correct | 1146 ms | 14340 KB | Output is correct |
12 | Correct | 95 ms | 13404 KB | Output is correct |
13 | Correct | 1356 ms | 15664 KB | Output is correct |
14 | Correct | 1316 ms | 15704 KB | Output is correct |
15 | Correct | 1273 ms | 15232 KB | Output is correct |
16 | Correct | 947 ms | 14876 KB | Output is correct |
17 | Correct | 215 ms | 14820 KB | Output is correct |
18 | Correct | 129 ms | 13796 KB | Output is correct |
19 | Correct | 1433 ms | 15660 KB | Output is correct |
20 | Correct | 1383 ms | 15640 KB | Output is correct |
21 | Correct | 811 ms | 15648 KB | Output is correct |
22 | Correct | 144 ms | 14432 KB | Output is correct |
23 | Correct | 840 ms | 14336 KB | Output is correct |
24 | Correct | 67 ms | 13404 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 212 KB | Output is correct |
3 | Correct | 1 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 212 KB | Output is correct |
5 | Correct | 1 ms | 212 KB | Output is correct |
6 | Correct | 1 ms | 212 KB | Output is correct |
7 | Correct | 14 ms | 608 KB | Output is correct |
8 | Correct | 9 ms | 724 KB | Output is correct |
9 | Correct | 10 ms | 724 KB | Output is correct |
10 | Correct | 9 ms | 632 KB | Output is correct |
11 | Correct | 6 ms | 596 KB | Output is correct |
12 | Correct | 7 ms | 724 KB | Output is correct |
13 | Correct | 14 ms | 832 KB | Output is correct |
14 | Correct | 9 ms | 744 KB | Output is correct |
15 | Correct | 10 ms | 852 KB | Output is correct |
16 | Correct | 4 ms | 712 KB | Output is correct |
17 | Correct | 7 ms | 752 KB | Output is correct |
18 | Correct | 4 ms | 716 KB | Output is correct |
19 | Correct | 1304 ms | 12728 KB | Output is correct |
20 | Correct | 1443 ms | 12732 KB | Output is correct |
21 | Correct | 1442 ms | 12728 KB | Output is correct |
22 | Correct | 998 ms | 12732 KB | Output is correct |
23 | Correct | 212 ms | 12728 KB | Output is correct |
24 | Correct | 159 ms | 12732 KB | Output is correct |
25 | Correct | 540 ms | 15140 KB | Output is correct |
26 | Correct | 656 ms | 15136 KB | Output is correct |
27 | Correct | 585 ms | 15052 KB | Output is correct |
28 | Correct | 206 ms | 14292 KB | Output is correct |
29 | Correct | 1146 ms | 14340 KB | Output is correct |
30 | Correct | 95 ms | 13404 KB | Output is correct |
31 | Correct | 1356 ms | 15664 KB | Output is correct |
32 | Correct | 1316 ms | 15704 KB | Output is correct |
33 | Correct | 1273 ms | 15232 KB | Output is correct |
34 | Correct | 947 ms | 14876 KB | Output is correct |
35 | Correct | 215 ms | 14820 KB | Output is correct |
36 | Correct | 129 ms | 13796 KB | Output is correct |
37 | Correct | 1433 ms | 15660 KB | Output is correct |
38 | Correct | 1383 ms | 15640 KB | Output is correct |
39 | Correct | 811 ms | 15648 KB | Output is correct |
40 | Correct | 144 ms | 14432 KB | Output is correct |
41 | Correct | 840 ms | 14336 KB | Output is correct |
42 | Correct | 67 ms | 13404 KB | Output is correct |
43 | Correct | 1308 ms | 17628 KB | Output is correct |
44 | Correct | 1273 ms | 17580 KB | Output is correct |
45 | Correct | 1268 ms | 17588 KB | Output is correct |
46 | Correct | 929 ms | 16052 KB | Output is correct |
47 | Correct | 227 ms | 16048 KB | Output is correct |
48 | Correct | 155 ms | 13568 KB | Output is correct |
49 | Correct | 564 ms | 17480 KB | Output is correct |
50 | Correct | 663 ms | 17528 KB | Output is correct |
51 | Correct | 566 ms | 17384 KB | Output is correct |
52 | Correct | 167 ms | 15884 KB | Output is correct |
53 | Correct | 865 ms | 15128 KB | Output is correct |