# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
879297 | 2023-11-27T05:57:35 Z | hasan2006 | Examination (JOI19_examination) | C++17 | 931 ms | 90776 KB |
#include <bits/stdc++.h> using namespace std; #define TL ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); #define rall(s) s.rbegin(),s.rend() #define all(s) s.begin(),s.end() #define pb push_back #define se second #define fi first #define ll long long #define ld long double #define YES cout<<"YES\n" #define Yes cout<<"Yes\n" #define yes cout<<"yes\n" #define NO cout<<"NO\n" #define No cout<<"No\n" #define no cout<<"no\n" const int N = 6e5 + 9 , mod = 1e9 + 7; ll a[N] = {}, b[N] , c[N] , d[N][3] , dp[N]; ll nn = 0; void add(int x , int y){ while(x <= nn){ d[x][y] += 1; x += (x & (-x)); } } ll get(int x , int y){ ll sum = 0; while(x > 0){ sum += d[x][y]; x -= (x & (-x)); } return sum; } void solve() { ll q , i , j , m ,n, z ,s = 0 , f, l , r , k , x , y , mn = 1e18 , mx = 0; cin>>n>>m; set<int>st; map<int,int>mp; vector<pair<int,pair<int,int>>>v; vector<pair<int,int>>v1; for(i = 1; i <= n; i++){ cin>>l>>r; st.insert(l); st.insert(r); st.insert(r + l); v.pb({l + r , {l , r}}); } sort(rall(v)); for(i = 1; i <= m; i++){ cin>>a[i]>>b[i]>>c[i]; v1.pb({c[i] , i}); st.insert(b[i]); st.insert(a[i]); st.insert(b[i] + a[i]); } sort(rall(v1)); for(auto it:st) mp[it] = ++nn; l = 0; vector<pair<int,int>>vc; for(auto to : v1){ if(a[to.se] + b[to.se] < c[to.se]){ while(l < v.size() && v[l].fi >= to.fi){ add(mp[v[l].se.fi] , 1); add(mp[v[l].se.se] , 2); l++; } s = -l; s += l - get(mp[a[to.se]] - 1 , 1); s += l - get(mp[b[to.se]] - 1, 2); dp[to.se] = s; }else { vc.pb({b[to.se] , to.se}); } } for(i = 0; i < v.size(); i++) swap(v[i].fi , v[i].se.se); sort(rall(vc)); sort(rall(v)); l = 0; for(auto to : vc){ while(l < v.size() && v[l].fi >= to.fi){ add(mp[v[l].se.fi] , 0); l++; } dp[to.se] = l - get(mp[a[to.se]] - 1 , 0); } for(i = 1; i <= m; i++) cout<<dp[i]<<"\n"; } int main(){ int t = 1; //cin>>t; while(t--) { solve(); } } // Author : حسن
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 6488 KB | Output is correct |
2 | Correct | 2 ms | 6488 KB | Output is correct |
3 | Correct | 1 ms | 8540 KB | Output is correct |
4 | Correct | 1 ms | 6492 KB | Output is correct |
5 | Correct | 1 ms | 6492 KB | Output is correct |
6 | Correct | 1 ms | 6492 KB | Output is correct |
7 | Correct | 13 ms | 8936 KB | Output is correct |
8 | Correct | 13 ms | 8796 KB | Output is correct |
9 | Correct | 13 ms | 8904 KB | Output is correct |
10 | Correct | 10 ms | 8028 KB | Output is correct |
11 | Correct | 9 ms | 8032 KB | Output is correct |
12 | Correct | 5 ms | 8676 KB | Output is correct |
13 | Correct | 12 ms | 10588 KB | Output is correct |
14 | Correct | 11 ms | 8796 KB | Output is correct |
15 | Correct | 11 ms | 10584 KB | Output is correct |
16 | Correct | 8 ms | 7516 KB | Output is correct |
17 | Correct | 8 ms | 7624 KB | Output is correct |
18 | Correct | 4 ms | 6748 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 309 ms | 35432 KB | Output is correct |
2 | Correct | 306 ms | 35084 KB | Output is correct |
3 | Correct | 316 ms | 34988 KB | Output is correct |
4 | Correct | 226 ms | 29324 KB | Output is correct |
5 | Correct | 186 ms | 25436 KB | Output is correct |
6 | Correct | 94 ms | 17792 KB | Output is correct |
7 | Correct | 302 ms | 33200 KB | Output is correct |
8 | Correct | 286 ms | 33668 KB | Output is correct |
9 | Correct | 274 ms | 32888 KB | Output is correct |
10 | Correct | 170 ms | 24584 KB | Output is correct |
11 | Correct | 193 ms | 26628 KB | Output is correct |
12 | Correct | 81 ms | 15552 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 309 ms | 35432 KB | Output is correct |
2 | Correct | 306 ms | 35084 KB | Output is correct |
3 | Correct | 316 ms | 34988 KB | Output is correct |
4 | Correct | 226 ms | 29324 KB | Output is correct |
5 | Correct | 186 ms | 25436 KB | Output is correct |
6 | Correct | 94 ms | 17792 KB | Output is correct |
7 | Correct | 302 ms | 33200 KB | Output is correct |
8 | Correct | 286 ms | 33668 KB | Output is correct |
9 | Correct | 274 ms | 32888 KB | Output is correct |
10 | Correct | 170 ms | 24584 KB | Output is correct |
11 | Correct | 193 ms | 26628 KB | Output is correct |
12 | Correct | 81 ms | 15552 KB | Output is correct |
13 | Correct | 365 ms | 33028 KB | Output is correct |
14 | Correct | 361 ms | 35736 KB | Output is correct |
15 | Correct | 300 ms | 35416 KB | Output is correct |
16 | Correct | 249 ms | 28796 KB | Output is correct |
17 | Correct | 229 ms | 28680 KB | Output is correct |
18 | Correct | 102 ms | 17812 KB | Output is correct |
19 | Correct | 397 ms | 32952 KB | Output is correct |
20 | Correct | 365 ms | 34820 KB | Output is correct |
21 | Correct | 361 ms | 32088 KB | Output is correct |
22 | Correct | 170 ms | 26632 KB | Output is correct |
23 | Correct | 204 ms | 26632 KB | Output is correct |
24 | Correct | 84 ms | 15484 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 6488 KB | Output is correct |
2 | Correct | 2 ms | 6488 KB | Output is correct |
3 | Correct | 1 ms | 8540 KB | Output is correct |
4 | Correct | 1 ms | 6492 KB | Output is correct |
5 | Correct | 1 ms | 6492 KB | Output is correct |
6 | Correct | 1 ms | 6492 KB | Output is correct |
7 | Correct | 13 ms | 8936 KB | Output is correct |
8 | Correct | 13 ms | 8796 KB | Output is correct |
9 | Correct | 13 ms | 8904 KB | Output is correct |
10 | Correct | 10 ms | 8028 KB | Output is correct |
11 | Correct | 9 ms | 8032 KB | Output is correct |
12 | Correct | 5 ms | 8676 KB | Output is correct |
13 | Correct | 12 ms | 10588 KB | Output is correct |
14 | Correct | 11 ms | 8796 KB | Output is correct |
15 | Correct | 11 ms | 10584 KB | Output is correct |
16 | Correct | 8 ms | 7516 KB | Output is correct |
17 | Correct | 8 ms | 7624 KB | Output is correct |
18 | Correct | 4 ms | 6748 KB | Output is correct |
19 | Correct | 309 ms | 35432 KB | Output is correct |
20 | Correct | 306 ms | 35084 KB | Output is correct |
21 | Correct | 316 ms | 34988 KB | Output is correct |
22 | Correct | 226 ms | 29324 KB | Output is correct |
23 | Correct | 186 ms | 25436 KB | Output is correct |
24 | Correct | 94 ms | 17792 KB | Output is correct |
25 | Correct | 302 ms | 33200 KB | Output is correct |
26 | Correct | 286 ms | 33668 KB | Output is correct |
27 | Correct | 274 ms | 32888 KB | Output is correct |
28 | Correct | 170 ms | 24584 KB | Output is correct |
29 | Correct | 193 ms | 26628 KB | Output is correct |
30 | Correct | 81 ms | 15552 KB | Output is correct |
31 | Correct | 365 ms | 33028 KB | Output is correct |
32 | Correct | 361 ms | 35736 KB | Output is correct |
33 | Correct | 300 ms | 35416 KB | Output is correct |
34 | Correct | 249 ms | 28796 KB | Output is correct |
35 | Correct | 229 ms | 28680 KB | Output is correct |
36 | Correct | 102 ms | 17812 KB | Output is correct |
37 | Correct | 397 ms | 32952 KB | Output is correct |
38 | Correct | 365 ms | 34820 KB | Output is correct |
39 | Correct | 361 ms | 32088 KB | Output is correct |
40 | Correct | 170 ms | 26632 KB | Output is correct |
41 | Correct | 204 ms | 26632 KB | Output is correct |
42 | Correct | 84 ms | 15484 KB | Output is correct |
43 | Correct | 922 ms | 87300 KB | Output is correct |
44 | Correct | 931 ms | 89344 KB | Output is correct |
45 | Correct | 889 ms | 90776 KB | Output is correct |
46 | Correct | 472 ms | 63492 KB | Output is correct |
47 | Correct | 399 ms | 62976 KB | Output is correct |
48 | Correct | 99 ms | 15180 KB | Output is correct |
49 | Correct | 882 ms | 89720 KB | Output is correct |
50 | Correct | 918 ms | 87716 KB | Output is correct |
51 | Correct | 808 ms | 88864 KB | Output is correct |
52 | Correct | 317 ms | 49152 KB | Output is correct |
53 | Correct | 293 ms | 46876 KB | Output is correct |