# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
493825 | 2021-12-13T05:03:32 Z | mars4 | Examination (JOI19_examination) | C++17 | 1149 ms | 110072 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 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 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--------------------------------- template<class T> class MergeSortTree { ll N; ll lesser_than(ll i,ll val) { ll res=0; for(;i;i-=i&(-i)) { res+=fentree[i].order_of_key(val); } return res; } ll greater_than(ll i,ll val) { ll res=0; for(;i;i-=i&(-i)) { res+=(ll)fentree[i].size()-fentree[i].order_of_key(val+1); } return res; } public: vector<ordered_set<T,less_equal<T>>> fentree; void init(ll n) { N=n; fentree=vector<ordered_set<T,less_equal<T>>>(N+1); } void build(vector<ll> &a) { for(ll i=1;i<=N;i++) { fentree[i].insert(a[i-1]); if(i+(i&-i)<=N) { for(ll j:fentree[i]) { fentree[i+(i&-i)].insert(j); } } } } void update(ll i,ll val) { for(i++;i<=N;i+=i&(-i)) { fentree[i].insert(val); } } ll lesser_than(ll l,ll r,ll val) { return lesser_than(r+1,val)-lesser_than(l,val); } ll greater_than(ll l,ll r,ll val) { return greater_than(r+1,val)-greater_than(l,val); } ll count(ll l,ll r,ll val) { ll len=r-l+1; ll gt=greater_than(l,r,val); ll lt=lesser_than(l,r,val); return len-gt-lt; } }; struct st { ll a,b,c,id; bool operator < (const st &o) const { return a<o.a; } }; int main() { fastio(); ll z,n,m,t,k,i,j,l,d,h,r; cin>>n>>m; vector<st> marks(n); vector<st> queries(m); vector<ll> comp; forn(i,0,n) { auto &[a,b,c,id]=marks[i]; cin>>a>>b; comp.push_back(b); c=a+b; id=i; } forn(i,0,m) { auto &[a,b,c,id]=queries[i]; cin>>a>>b>>c; comp.push_back(b); id=i; } sort(all(comp)); for(auto &[a,b,c,id]:marks) { b=lower_bound(all(comp),b)-comp.begin(); } for(auto &[a,b,c,id]:queries) { b=lower_bound(all(comp),b)-comp.begin(); } sort(all(marks)); sort(all(queries)); MergeSortTree<int> mt; mt.init(n+m); vector<ll> ans(m); j=m-1; forb(i,n-1,0) { auto [a,b,c,id]=marks[i]; while(j>=0 and queries[j].a>a) { ans[queries[j].id]=mt.greater_than(queries[j].b,n+m-1,queries[j].c-1); j--; } mt.update(b,c); } while(j>=0) { ans[queries[j].id]=mt.greater_than(queries[j].b,n+m-1,queries[j].c-1); j--; } 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 | 1 ms | 204 KB | Output is correct |
2 | Correct | 0 ms | 204 KB | Output is correct |
3 | Correct | 1 ms | 204 KB | Output is correct |
4 | Correct | 1 ms | 204 KB | Output is correct |
5 | Correct | 1 ms | 204 KB | Output is correct |
6 | Correct | 0 ms | 312 KB | Output is correct |
7 | Correct | 9 ms | 2124 KB | Output is correct |
8 | Correct | 9 ms | 2116 KB | Output is correct |
9 | Correct | 9 ms | 2124 KB | Output is correct |
10 | Correct | 9 ms | 2252 KB | Output is correct |
11 | Correct | 8 ms | 2016 KB | Output is correct |
12 | Correct | 8 ms | 1996 KB | Output is correct |
13 | Correct | 9 ms | 2064 KB | Output is correct |
14 | Correct | 8 ms | 2124 KB | Output is correct |
15 | Correct | 9 ms | 2016 KB | Output is correct |
16 | Correct | 7 ms | 1996 KB | Output is correct |
17 | Correct | 12 ms | 2920 KB | Output is correct |
18 | Correct | 11 ms | 2892 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 823 ms | 69124 KB | Output is correct |
2 | Correct | 843 ms | 69028 KB | Output is correct |
3 | Correct | 813 ms | 69196 KB | Output is correct |
4 | Correct | 440 ms | 75904 KB | Output is correct |
5 | Correct | 608 ms | 69008 KB | Output is correct |
6 | Correct | 396 ms | 71348 KB | Output is correct |
7 | Correct | 905 ms | 69316 KB | Output is correct |
8 | Correct | 736 ms | 66848 KB | Output is correct |
9 | Correct | 758 ms | 66868 KB | Output is correct |
10 | Correct | 666 ms | 68920 KB | Output is correct |
11 | Correct | 751 ms | 109892 KB | Output is correct |
12 | Correct | 1104 ms | 109960 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 823 ms | 69124 KB | Output is correct |
2 | Correct | 843 ms | 69028 KB | Output is correct |
3 | Correct | 813 ms | 69196 KB | Output is correct |
4 | Correct | 440 ms | 75904 KB | Output is correct |
5 | Correct | 608 ms | 69008 KB | Output is correct |
6 | Correct | 396 ms | 71348 KB | Output is correct |
7 | Correct | 905 ms | 69316 KB | Output is correct |
8 | Correct | 736 ms | 66848 KB | Output is correct |
9 | Correct | 758 ms | 66868 KB | Output is correct |
10 | Correct | 666 ms | 68920 KB | Output is correct |
11 | Correct | 751 ms | 109892 KB | Output is correct |
12 | Correct | 1104 ms | 109960 KB | Output is correct |
13 | Correct | 1049 ms | 68988 KB | Output is correct |
14 | Correct | 855 ms | 69216 KB | Output is correct |
15 | Correct | 828 ms | 69108 KB | Output is correct |
16 | Correct | 687 ms | 76236 KB | Output is correct |
17 | Correct | 729 ms | 69244 KB | Output is correct |
18 | Correct | 491 ms | 75376 KB | Output is correct |
19 | Correct | 1016 ms | 69220 KB | Output is correct |
20 | Correct | 976 ms | 69000 KB | Output is correct |
21 | Correct | 1142 ms | 67888 KB | Output is correct |
22 | Correct | 583 ms | 68960 KB | Output is correct |
23 | Correct | 811 ms | 109824 KB | Output is correct |
24 | Correct | 1149 ms | 109740 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 204 KB | Output is correct |
2 | Correct | 0 ms | 204 KB | Output is correct |
3 | Correct | 1 ms | 204 KB | Output is correct |
4 | Correct | 1 ms | 204 KB | Output is correct |
5 | Correct | 1 ms | 204 KB | Output is correct |
6 | Correct | 0 ms | 312 KB | Output is correct |
7 | Correct | 9 ms | 2124 KB | Output is correct |
8 | Correct | 9 ms | 2116 KB | Output is correct |
9 | Correct | 9 ms | 2124 KB | Output is correct |
10 | Correct | 9 ms | 2252 KB | Output is correct |
11 | Correct | 8 ms | 2016 KB | Output is correct |
12 | Correct | 8 ms | 1996 KB | Output is correct |
13 | Correct | 9 ms | 2064 KB | Output is correct |
14 | Correct | 8 ms | 2124 KB | Output is correct |
15 | Correct | 9 ms | 2016 KB | Output is correct |
16 | Correct | 7 ms | 1996 KB | Output is correct |
17 | Correct | 12 ms | 2920 KB | Output is correct |
18 | Correct | 11 ms | 2892 KB | Output is correct |
19 | Correct | 823 ms | 69124 KB | Output is correct |
20 | Correct | 843 ms | 69028 KB | Output is correct |
21 | Correct | 813 ms | 69196 KB | Output is correct |
22 | Correct | 440 ms | 75904 KB | Output is correct |
23 | Correct | 608 ms | 69008 KB | Output is correct |
24 | Correct | 396 ms | 71348 KB | Output is correct |
25 | Correct | 905 ms | 69316 KB | Output is correct |
26 | Correct | 736 ms | 66848 KB | Output is correct |
27 | Correct | 758 ms | 66868 KB | Output is correct |
28 | Correct | 666 ms | 68920 KB | Output is correct |
29 | Correct | 751 ms | 109892 KB | Output is correct |
30 | Correct | 1104 ms | 109960 KB | Output is correct |
31 | Correct | 1049 ms | 68988 KB | Output is correct |
32 | Correct | 855 ms | 69216 KB | Output is correct |
33 | Correct | 828 ms | 69108 KB | Output is correct |
34 | Correct | 687 ms | 76236 KB | Output is correct |
35 | Correct | 729 ms | 69244 KB | Output is correct |
36 | Correct | 491 ms | 75376 KB | Output is correct |
37 | Correct | 1016 ms | 69220 KB | Output is correct |
38 | Correct | 976 ms | 69000 KB | Output is correct |
39 | Correct | 1142 ms | 67888 KB | Output is correct |
40 | Correct | 583 ms | 68960 KB | Output is correct |
41 | Correct | 811 ms | 109824 KB | Output is correct |
42 | Correct | 1149 ms | 109740 KB | Output is correct |
43 | Correct | 1050 ms | 69060 KB | Output is correct |
44 | Correct | 1034 ms | 68988 KB | Output is correct |
45 | Correct | 933 ms | 69120 KB | Output is correct |
46 | Correct | 597 ms | 73700 KB | Output is correct |
47 | Correct | 730 ms | 69052 KB | Output is correct |
48 | Correct | 433 ms | 72608 KB | Output is correct |
49 | Correct | 1118 ms | 69244 KB | Output is correct |
50 | Correct | 908 ms | 66848 KB | Output is correct |
51 | Correct | 1002 ms | 66744 KB | Output is correct |
52 | Correct | 693 ms | 69052 KB | Output is correct |
53 | Correct | 1126 ms | 110072 KB | Output is correct |