Submission #998388

# Submission time Handle Problem Language Result Execution time Memory
998388 2024-06-13T19:21:41 Z vjudge1 Examination (JOI19_examination) C++17
100 / 100
899 ms 56248 KB
#include <bits/stdc++.h>
using namespace std;
#define all(a) a.begin(), a.end()
#define ll long long
#define endl '\n'
const int N = 1e6 + 6, LOG = 27, MOD = 1e9 + 7;
const ll INF = 1e18;
void solver();
signed main() {
  cin.tie(0)->sync_with_stdio(0);
  int t = 1; // cin>>t;
  while (t--)
    solver();
}
int n,q; 
ll res[N],max_val = 1;
struct op{
    ll x = 0,y = 0,z = 0; int idx = 0,val = 0;
    op(ll x,ll y,ll z,int i,int v):x(x),y(y),z(z),idx(i),val(v){}
    bool operator < (const op &b) const{
        op a = *this;
        if(a.x == b.x) return a.val > b.val;
	    return (a.x == b.x ? (a.y == b.y ? a.z < b.z : a.y < b.y) : a.x > b.x);
    }
};

vector<op>v;
void compress(){
    map<ll,int>mp;
    for(int i = 0;i < n + q;++i){
        mp[v[i].x] = true;
        mp[v[i].y] = true;
        mp[v[i].z] = true;
    }
	for(auto i : mp) mp[i.first] = max_val++;
	for(int i = 0; i < n + q; i++){
		v[i].x = mp[v[i].x];
		v[i].y = mp[v[i].y];
		v[i].z = mp[v[i].z];
	}
}

namespace bit{
    ll tr[N];
    int lowbit(int i){return i&(-i);}
    void update(int i,ll val){
        for(;i <= max_val;i += lowbit(i)) tr[i] += val;
    }
    ll get(int l,int r){
        auto sum=[&](int i){
            ll res = 0;
            for(;i > 0;i-=lowbit(i)) res += tr[i];
            return res;
        };
        return sum(r) - sum(l - 1);
    } 
};

void calc_cont(int l,int m,int r){
    int a = l,b = m + 1;
    vector<op>tmp; vector<pair<int,int>>record;
    while(a <= m && b <= r){
        if(v[a].y >= v[b].y){
            bit::update(v[a].z,v[a].val);            
            record.emplace_back(v[a].z,v[a].val);
            tmp.push_back(v[a]);
            ++a;
        }else{
            res[v[b].idx] += bit::get(v[b].z,max_val);
            tmp.push_back(v[b]);
            ++b;
        }
    }
    while(a <= m){
        tmp.push_back(v[a]);
        ++a;
    }
    while(b <= r){
        res[v[b].idx] += bit::get(v[b].z,max_val);
        tmp.push_back(v[b]);
        ++b;
    }
    for(int i = l;i <= r;++i) v[i] = tmp[i - l];
    for(auto &[pos,val] : record) bit::update(pos,-val);
}

void cdq(int l,int r){
    if(l == r) return;
    int m = (r+l) >> 1; 
    cdq(l,m); cdq(m+1,r);
    calc_cont(l,m,r);
}

void solver() {
    cin>>n>>q;
    for(int i = 0;i < n;++i){
        ll x,y; cin>>x>>y;
        v.push_back({x,y,x + y,i,1});
    }    
    for(int i = n;i < n + q;++i){
        ll x,y,z; cin>>x>>y>>z;
        v.push_back({x,y,z,i,0});
    }
    compress();
    sort(v.begin(),v.end());
    cdq(0,n + q - 1);
    for(int i = n;i < n + q;++i) cout<<res[i]<<endl; 
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 2392 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 12 ms 3816 KB Output is correct
8 Correct 12 ms 3988 KB Output is correct
9 Correct 12 ms 3872 KB Output is correct
10 Correct 10 ms 3552 KB Output is correct
11 Correct 9 ms 3552 KB Output is correct
12 Correct 4 ms 3100 KB Output is correct
13 Correct 10 ms 3564 KB Output is correct
14 Correct 10 ms 3548 KB Output is correct
15 Correct 10 ms 3552 KB Output is correct
16 Correct 6 ms 3312 KB Output is correct
17 Correct 8 ms 3348 KB Output is correct
18 Correct 3 ms 3192 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 458 ms 31664 KB Output is correct
2 Correct 437 ms 31668 KB Output is correct
3 Correct 437 ms 32180 KB Output is correct
4 Correct 310 ms 30912 KB Output is correct
5 Correct 305 ms 30384 KB Output is correct
6 Correct 110 ms 27872 KB Output is correct
7 Correct 414 ms 30456 KB Output is correct
8 Correct 439 ms 34744 KB Output is correct
9 Correct 389 ms 32196 KB Output is correct
10 Correct 263 ms 29312 KB Output is correct
11 Correct 274 ms 31160 KB Output is correct
12 Correct 84 ms 28032 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 458 ms 31664 KB Output is correct
2 Correct 437 ms 31668 KB Output is correct
3 Correct 437 ms 32180 KB Output is correct
4 Correct 310 ms 30912 KB Output is correct
5 Correct 305 ms 30384 KB Output is correct
6 Correct 110 ms 27872 KB Output is correct
7 Correct 414 ms 30456 KB Output is correct
8 Correct 439 ms 34744 KB Output is correct
9 Correct 389 ms 32196 KB Output is correct
10 Correct 263 ms 29312 KB Output is correct
11 Correct 274 ms 31160 KB Output is correct
12 Correct 84 ms 28032 KB Output is correct
13 Correct 481 ms 29184 KB Output is correct
14 Correct 485 ms 31960 KB Output is correct
15 Correct 427 ms 33212 KB Output is correct
16 Correct 335 ms 30900 KB Output is correct
17 Correct 353 ms 30220 KB Output is correct
18 Correct 126 ms 26488 KB Output is correct
19 Correct 521 ms 29880 KB Output is correct
20 Correct 492 ms 34232 KB Output is correct
21 Correct 463 ms 28340 KB Output is correct
22 Correct 272 ms 31956 KB Output is correct
23 Correct 283 ms 34232 KB Output is correct
24 Correct 88 ms 28740 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 2392 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 12 ms 3816 KB Output is correct
8 Correct 12 ms 3988 KB Output is correct
9 Correct 12 ms 3872 KB Output is correct
10 Correct 10 ms 3552 KB Output is correct
11 Correct 9 ms 3552 KB Output is correct
12 Correct 4 ms 3100 KB Output is correct
13 Correct 10 ms 3564 KB Output is correct
14 Correct 10 ms 3548 KB Output is correct
15 Correct 10 ms 3552 KB Output is correct
16 Correct 6 ms 3312 KB Output is correct
17 Correct 8 ms 3348 KB Output is correct
18 Correct 3 ms 3192 KB Output is correct
19 Correct 458 ms 31664 KB Output is correct
20 Correct 437 ms 31668 KB Output is correct
21 Correct 437 ms 32180 KB Output is correct
22 Correct 310 ms 30912 KB Output is correct
23 Correct 305 ms 30384 KB Output is correct
24 Correct 110 ms 27872 KB Output is correct
25 Correct 414 ms 30456 KB Output is correct
26 Correct 439 ms 34744 KB Output is correct
27 Correct 389 ms 32196 KB Output is correct
28 Correct 263 ms 29312 KB Output is correct
29 Correct 274 ms 31160 KB Output is correct
30 Correct 84 ms 28032 KB Output is correct
31 Correct 481 ms 29184 KB Output is correct
32 Correct 485 ms 31960 KB Output is correct
33 Correct 427 ms 33212 KB Output is correct
34 Correct 335 ms 30900 KB Output is correct
35 Correct 353 ms 30220 KB Output is correct
36 Correct 126 ms 26488 KB Output is correct
37 Correct 521 ms 29880 KB Output is correct
38 Correct 492 ms 34232 KB Output is correct
39 Correct 463 ms 28340 KB Output is correct
40 Correct 272 ms 31956 KB Output is correct
41 Correct 283 ms 34232 KB Output is correct
42 Correct 88 ms 28740 KB Output is correct
43 Correct 879 ms 54232 KB Output is correct
44 Correct 889 ms 53852 KB Output is correct
45 Correct 899 ms 56248 KB Output is correct
46 Correct 517 ms 40120 KB Output is correct
47 Correct 546 ms 45236 KB Output is correct
48 Correct 136 ms 27504 KB Output is correct
49 Correct 853 ms 54772 KB Output is correct
50 Correct 847 ms 55224 KB Output is correct
51 Correct 806 ms 55216 KB Output is correct
52 Correct 443 ms 40116 KB Output is correct
53 Correct 347 ms 31160 KB Output is correct