Submission #998050

# Submission time Handle Problem Language Result Execution time Memory
998050 2024-06-13T08:53:18 Z khanhtb Examination (JOI19_examination) C++17
100 / 100
328 ms 40052 KB
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define ld double
#define pb push_back
#define pf push_front
#define vi vector<ll>
#define vii vector<vi>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define all(a) a.begin(), a.end()
#define fi first
#define se second
using namespace std;
const ll mod = 1e9+7;   
const ll inf = 2e18;
const ll base = 31;
const ll blocksz = 320;
const ll N = 2e5+8;
ll n,q;
struct point{
    ll x,y,z,id;
} a[N];
struct Binary_Indexed_Tree{
    ll BIT[N]; 
    void update(ll i, ll x){
        while(i <= n+q){
            BIT[i] += x;
            i += (i&-i);
        }
    }
    ll get(ll i){
        ll ans = 0;
        while(i){
            ans += BIT[i];
            i -= (i&-i);
        }
        return ans;
    }
} bit;
ll ans[N];
void cdq(ll l, ll r){
    if(l == r) return;
    ll m = l+r>>1;
    cdq(l,m),cdq(m+1,r);
    vector<point> pts;
    vi reset;
    ll i = l, j = m+1, cnt = 0;
    while(i <= m && j <= r){
        if(a[i].y > a[j].y){
            if(a[i].id <= n) bit.update(a[i].z,1),cnt++,reset.pb(a[i].z);
            pts.pb(a[i++]);
        }
        else{
            if(a[j].id > n) ans[a[j].id] += cnt-bit.get(a[j].z);
            pts.pb(a[j++]);
        }
    }
    while(i <= m){
        if(a[i].id <= n) bit.update(a[i].z,1),cnt++,reset.pb(a[i].z);
        pts.pb(a[i++]);
    }
    while(j <= r){
        if(a[j].id > n) ans[a[j].id] += cnt-bit.get(a[j].z);
        pts.pb(a[j++]);
    }
    for (ll i = l; i <= r; ++i) a[i] = pts[i-l];
    for (ll i:reset) bit.update(i,-1);
}   
map<ll,ll> comp;
void solve(){
    cin >> n >> q;
    vi compress;
    for(ll i = 1; i <= n; i++){
        cin >> a[i].x >> a[i].y;
        a[i].id = i;
        a[i].z = a[i].x+a[i].y;
        compress.pb(a[i].z);
    }
    for(ll i = n+1; i <= n+q; i++){
        cin >> a[i].x >> a[i].y >> a[i].z;
        a[i].x--, a[i].y--, a[i].z--;
        a[i].id = i;
        compress.pb(a[i].z);
    }
    sort(all(compress));
    compress.erase(unique(all(compress)),compress.end());
    for(ll i = 1; i <= compress.size(); i++){
        comp[compress[i-1]] = i;
    }
    for(ll i = 1; i <= n+q; i++) a[i].z = comp[a[i].z];
    sort(a+1,a+n+q+1,[&](point x, point y){
        return x.x > y.x || (x.x == y.x && (x.y < y.y || (x.y == y.y && x.z < y.z)));
    });
    cdq(1,n+q);
    for(ll i = n+1; i <= n+q; i++){
        cout << ans[i] << '\n';
    }
}   
signed main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    if(fopen("test.inp","r")){
        freopen("test.inp","r",stdin);
        freopen("test.out","w",stdout);
    }
    ll T = 1;
    // cin >> T;
    while(T--){
        solve();
        cout << '\n';
    }
} 

Compilation message

examination.cpp: In function 'void cdq(long long int, long long int)':
examination.cpp:44:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   44 |     ll m = l+r>>1;
      |            ~^~
examination.cpp: In function 'void solve()':
examination.cpp:88:21: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   88 |     for(ll i = 1; i <= compress.size(); i++){
      |                   ~~^~~~~~~~~~~~~~~~~~
examination.cpp: In function 'int main()':
examination.cpp:103:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  103 |         freopen("test.inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
examination.cpp:104:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  104 |         freopen("test.out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4440 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 7 ms 5276 KB Output is correct
8 Correct 6 ms 3372 KB Output is correct
9 Correct 7 ms 5276 KB Output is correct
10 Correct 8 ms 3388 KB Output is correct
11 Correct 6 ms 5276 KB Output is correct
12 Correct 4 ms 5048 KB Output is correct
13 Correct 5 ms 3068 KB Output is correct
14 Correct 5 ms 5160 KB Output is correct
15 Correct 5 ms 3196 KB Output is correct
16 Correct 5 ms 5168 KB Output is correct
17 Correct 6 ms 5276 KB Output is correct
18 Correct 3 ms 3000 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 215 ms 30712 KB Output is correct
2 Correct 224 ms 30696 KB Output is correct
3 Correct 216 ms 31952 KB Output is correct
4 Correct 200 ms 30092 KB Output is correct
5 Correct 197 ms 31520 KB Output is correct
6 Correct 158 ms 26728 KB Output is correct
7 Correct 206 ms 30148 KB Output is correct
8 Correct 204 ms 31324 KB Output is correct
9 Correct 205 ms 31820 KB Output is correct
10 Correct 182 ms 30020 KB Output is correct
11 Correct 180 ms 30336 KB Output is correct
12 Correct 147 ms 24720 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 215 ms 30712 KB Output is correct
2 Correct 224 ms 30696 KB Output is correct
3 Correct 216 ms 31952 KB Output is correct
4 Correct 200 ms 30092 KB Output is correct
5 Correct 197 ms 31520 KB Output is correct
6 Correct 158 ms 26728 KB Output is correct
7 Correct 206 ms 30148 KB Output is correct
8 Correct 204 ms 31324 KB Output is correct
9 Correct 205 ms 31820 KB Output is correct
10 Correct 182 ms 30020 KB Output is correct
11 Correct 180 ms 30336 KB Output is correct
12 Correct 147 ms 24720 KB Output is correct
13 Correct 268 ms 34380 KB Output is correct
14 Correct 270 ms 32988 KB Output is correct
15 Correct 225 ms 31852 KB Output is correct
16 Correct 242 ms 32160 KB Output is correct
17 Correct 252 ms 32052 KB Output is correct
18 Correct 170 ms 26896 KB Output is correct
19 Correct 285 ms 34452 KB Output is correct
20 Correct 273 ms 32740 KB Output is correct
21 Correct 275 ms 34436 KB Output is correct
22 Correct 185 ms 30672 KB Output is correct
23 Correct 181 ms 29956 KB Output is correct
24 Correct 146 ms 24728 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4440 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 7 ms 5276 KB Output is correct
8 Correct 6 ms 3372 KB Output is correct
9 Correct 7 ms 5276 KB Output is correct
10 Correct 8 ms 3388 KB Output is correct
11 Correct 6 ms 5276 KB Output is correct
12 Correct 4 ms 5048 KB Output is correct
13 Correct 5 ms 3068 KB Output is correct
14 Correct 5 ms 5160 KB Output is correct
15 Correct 5 ms 3196 KB Output is correct
16 Correct 5 ms 5168 KB Output is correct
17 Correct 6 ms 5276 KB Output is correct
18 Correct 3 ms 3000 KB Output is correct
19 Correct 215 ms 30712 KB Output is correct
20 Correct 224 ms 30696 KB Output is correct
21 Correct 216 ms 31952 KB Output is correct
22 Correct 200 ms 30092 KB Output is correct
23 Correct 197 ms 31520 KB Output is correct
24 Correct 158 ms 26728 KB Output is correct
25 Correct 206 ms 30148 KB Output is correct
26 Correct 204 ms 31324 KB Output is correct
27 Correct 205 ms 31820 KB Output is correct
28 Correct 182 ms 30020 KB Output is correct
29 Correct 180 ms 30336 KB Output is correct
30 Correct 147 ms 24720 KB Output is correct
31 Correct 268 ms 34380 KB Output is correct
32 Correct 270 ms 32988 KB Output is correct
33 Correct 225 ms 31852 KB Output is correct
34 Correct 242 ms 32160 KB Output is correct
35 Correct 252 ms 32052 KB Output is correct
36 Correct 170 ms 26896 KB Output is correct
37 Correct 285 ms 34452 KB Output is correct
38 Correct 273 ms 32740 KB Output is correct
39 Correct 275 ms 34436 KB Output is correct
40 Correct 185 ms 30672 KB Output is correct
41 Correct 181 ms 29956 KB Output is correct
42 Correct 146 ms 24728 KB Output is correct
43 Correct 323 ms 38940 KB Output is correct
44 Correct 305 ms 39392 KB Output is correct
45 Correct 328 ms 39356 KB Output is correct
46 Correct 284 ms 37648 KB Output is correct
47 Correct 286 ms 40020 KB Output is correct
48 Correct 169 ms 26580 KB Output is correct
49 Correct 284 ms 38532 KB Output is correct
50 Correct 303 ms 38252 KB Output is correct
51 Correct 290 ms 39596 KB Output is correct
52 Correct 268 ms 40052 KB Output is correct
53 Correct 212 ms 31156 KB Output is correct