# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
493824 | 2021-12-13T05:02:26 Z | mars4 | Examination (JOI19_examination) | C++17 | 1723 ms | 143636 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<ll> 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 | 1 ms | 308 KB | Output is correct |
3 | Correct | 1 ms | 204 KB | Output is correct |
4 | Correct | 0 ms | 204 KB | Output is correct |
5 | Correct | 0 ms | 204 KB | Output is correct |
6 | Correct | 0 ms | 204 KB | Output is correct |
7 | Correct | 9 ms | 2508 KB | Output is correct |
8 | Correct | 13 ms | 2540 KB | Output is correct |
9 | Correct | 13 ms | 2504 KB | Output is correct |
10 | Correct | 9 ms | 2636 KB | Output is correct |
11 | Correct | 9 ms | 2380 KB | Output is correct |
12 | Correct | 12 ms | 2508 KB | Output is correct |
13 | Correct | 9 ms | 2488 KB | Output is correct |
14 | Correct | 9 ms | 2496 KB | Output is correct |
15 | Correct | 8 ms | 2508 KB | Output is correct |
16 | Correct | 8 ms | 2380 KB | Output is correct |
17 | Correct | 14 ms | 3660 KB | Output is correct |
18 | Correct | 13 ms | 3532 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 888 ms | 88956 KB | Output is correct |
2 | Correct | 837 ms | 88964 KB | Output is correct |
3 | Correct | 885 ms | 89028 KB | Output is correct |
4 | Correct | 464 ms | 97204 KB | Output is correct |
5 | Correct | 644 ms | 88124 KB | Output is correct |
6 | Correct | 405 ms | 90196 KB | Output is correct |
7 | Correct | 1040 ms | 89084 KB | Output is correct |
8 | Correct | 836 ms | 85772 KB | Output is correct |
9 | Correct | 817 ms | 85472 KB | Output is correct |
10 | Correct | 547 ms | 87992 KB | Output is correct |
11 | Correct | 721 ms | 142604 KB | Output is correct |
12 | Correct | 1723 ms | 141568 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 888 ms | 88956 KB | Output is correct |
2 | Correct | 837 ms | 88964 KB | Output is correct |
3 | Correct | 885 ms | 89028 KB | Output is correct |
4 | Correct | 464 ms | 97204 KB | Output is correct |
5 | Correct | 644 ms | 88124 KB | Output is correct |
6 | Correct | 405 ms | 90196 KB | Output is correct |
7 | Correct | 1040 ms | 89084 KB | Output is correct |
8 | Correct | 836 ms | 85772 KB | Output is correct |
9 | Correct | 817 ms | 85472 KB | Output is correct |
10 | Correct | 547 ms | 87992 KB | Output is correct |
11 | Correct | 721 ms | 142604 KB | Output is correct |
12 | Correct | 1723 ms | 141568 KB | Output is correct |
13 | Correct | 1047 ms | 89220 KB | Output is correct |
14 | Correct | 970 ms | 89240 KB | Output is correct |
15 | Correct | 841 ms | 89020 KB | Output is correct |
16 | Correct | 563 ms | 98140 KB | Output is correct |
17 | Correct | 726 ms | 88568 KB | Output is correct |
18 | Correct | 439 ms | 95936 KB | Output is correct |
19 | Correct | 1025 ms | 89436 KB | Output is correct |
20 | Correct | 964 ms | 89336 KB | Output is correct |
21 | Correct | 1074 ms | 87512 KB | Output is correct |
22 | Correct | 585 ms | 88068 KB | Output is correct |
23 | Correct | 745 ms | 142556 KB | Output is correct |
24 | Correct | 1666 ms | 141540 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 204 KB | Output is correct |
2 | Correct | 1 ms | 308 KB | Output is correct |
3 | Correct | 1 ms | 204 KB | Output is correct |
4 | Correct | 0 ms | 204 KB | Output is correct |
5 | Correct | 0 ms | 204 KB | Output is correct |
6 | Correct | 0 ms | 204 KB | Output is correct |
7 | Correct | 9 ms | 2508 KB | Output is correct |
8 | Correct | 13 ms | 2540 KB | Output is correct |
9 | Correct | 13 ms | 2504 KB | Output is correct |
10 | Correct | 9 ms | 2636 KB | Output is correct |
11 | Correct | 9 ms | 2380 KB | Output is correct |
12 | Correct | 12 ms | 2508 KB | Output is correct |
13 | Correct | 9 ms | 2488 KB | Output is correct |
14 | Correct | 9 ms | 2496 KB | Output is correct |
15 | Correct | 8 ms | 2508 KB | Output is correct |
16 | Correct | 8 ms | 2380 KB | Output is correct |
17 | Correct | 14 ms | 3660 KB | Output is correct |
18 | Correct | 13 ms | 3532 KB | Output is correct |
19 | Correct | 888 ms | 88956 KB | Output is correct |
20 | Correct | 837 ms | 88964 KB | Output is correct |
21 | Correct | 885 ms | 89028 KB | Output is correct |
22 | Correct | 464 ms | 97204 KB | Output is correct |
23 | Correct | 644 ms | 88124 KB | Output is correct |
24 | Correct | 405 ms | 90196 KB | Output is correct |
25 | Correct | 1040 ms | 89084 KB | Output is correct |
26 | Correct | 836 ms | 85772 KB | Output is correct |
27 | Correct | 817 ms | 85472 KB | Output is correct |
28 | Correct | 547 ms | 87992 KB | Output is correct |
29 | Correct | 721 ms | 142604 KB | Output is correct |
30 | Correct | 1723 ms | 141568 KB | Output is correct |
31 | Correct | 1047 ms | 89220 KB | Output is correct |
32 | Correct | 970 ms | 89240 KB | Output is correct |
33 | Correct | 841 ms | 89020 KB | Output is correct |
34 | Correct | 563 ms | 98140 KB | Output is correct |
35 | Correct | 726 ms | 88568 KB | Output is correct |
36 | Correct | 439 ms | 95936 KB | Output is correct |
37 | Correct | 1025 ms | 89436 KB | Output is correct |
38 | Correct | 964 ms | 89336 KB | Output is correct |
39 | Correct | 1074 ms | 87512 KB | Output is correct |
40 | Correct | 585 ms | 88068 KB | Output is correct |
41 | Correct | 745 ms | 142556 KB | Output is correct |
42 | Correct | 1666 ms | 141540 KB | Output is correct |
43 | Correct | 1037 ms | 91200 KB | Output is correct |
44 | Correct | 1031 ms | 91196 KB | Output is correct |
45 | Correct | 892 ms | 91440 KB | Output is correct |
46 | Correct | 560 ms | 95848 KB | Output is correct |
47 | Correct | 756 ms | 89692 KB | Output is correct |
48 | Correct | 445 ms | 92248 KB | Output is correct |
49 | Correct | 1144 ms | 91196 KB | Output is correct |
50 | Correct | 899 ms | 87944 KB | Output is correct |
51 | Correct | 920 ms | 87880 KB | Output is correct |
52 | Correct | 677 ms | 89488 KB | Output is correct |
53 | Correct | 1576 ms | 143636 KB | Output is correct |