Submission #879292

# Submission time Handle Problem Language Result Execution time Memory
879292 2023-11-27T05:52:28 Z hasan2006 Examination (JOI19_examination) C++17
43 / 100
940 ms 84244 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 = 5e5 + 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

examination.cpp: In function 'void solve()':
examination.cpp:72:17: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<int, std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   72 |         while(l < v.size() && v[l].fi >= to.fi){
      |               ~~^~~~~~~~~~
examination.cpp:85:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<int, std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   85 |     for(i = 0; i < v.size(); i++)
      |                ~~^~~~~~~~~~
examination.cpp:91:17: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<int, std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   91 |         while(l < v.size() && v[l].fi >= to.fi){
      |               ~~^~~~~~~~~~
examination.cpp:44:8: warning: unused variable 'q' [-Wunused-variable]
   44 |     ll q , i , j , m ,n, z ,s = 0 , f, l , r , k , x , y , mn  = 1e18 , mx = 0;
      |        ^
examination.cpp:44:16: warning: unused variable 'j' [-Wunused-variable]
   44 |     ll q , i , j , m ,n, z ,s = 0 , f, l , r , k , x , y , mn  = 1e18 , mx = 0;
      |                ^
examination.cpp:44:26: warning: unused variable 'z' [-Wunused-variable]
   44 |     ll q , i , j , m ,n, z ,s = 0 , f, l , r , k , x , y , mn  = 1e18 , mx = 0;
      |                          ^
examination.cpp:44:37: warning: unused variable 'f' [-Wunused-variable]
   44 |     ll q , i , j , m ,n, z ,s = 0 , f, l , r , k , x , y , mn  = 1e18 , mx = 0;
      |                                     ^
examination.cpp:44:48: warning: unused variable 'k' [-Wunused-variable]
   44 |     ll q , i , j , m ,n, z ,s = 0 , f, l , r , k , x , y , mn  = 1e18 , mx = 0;
      |                                                ^
examination.cpp:44:52: warning: unused variable 'x' [-Wunused-variable]
   44 |     ll q , i , j , m ,n, z ,s = 0 , f, l , r , k , x , y , mn  = 1e18 , mx = 0;
      |                                                    ^
examination.cpp:44:56: warning: unused variable 'y' [-Wunused-variable]
   44 |     ll q , i , j , m ,n, z ,s = 0 , f, l , r , k , x , y , mn  = 1e18 , mx = 0;
      |                                                        ^
examination.cpp:44:60: warning: unused variable 'mn' [-Wunused-variable]
   44 |     ll q , i , j , m ,n, z ,s = 0 , f, l , r , k , x , y , mn  = 1e18 , mx = 0;
      |                                                            ^~
examination.cpp:44:73: warning: unused variable 'mx' [-Wunused-variable]
   44 |     ll q , i , j , m ,n, z ,s = 0 , f, l , r , k , x , y , mn  = 1e18 , mx = 0;
      |                                                                         ^~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6488 KB Output is correct
2 Correct 1 ms 6492 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 10980 KB Output is correct
8 Correct 14 ms 10844 KB Output is correct
9 Correct 13 ms 10844 KB Output is correct
10 Correct 9 ms 8028 KB Output is correct
11 Correct 8 ms 8112 KB Output is correct
12 Correct 4 ms 8792 KB Output is correct
13 Correct 12 ms 12548 KB Output is correct
14 Correct 12 ms 10844 KB Output is correct
15 Correct 14 ms 12636 KB Output is correct
16 Correct 7 ms 7560 KB Output is correct
17 Correct 8 ms 7516 KB Output is correct
18 Correct 3 ms 6748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 325 ms 34568 KB Output is correct
2 Correct 302 ms 34576 KB Output is correct
3 Correct 333 ms 34504 KB Output is correct
4 Correct 215 ms 28048 KB Output is correct
5 Correct 189 ms 26112 KB Output is correct
6 Correct 94 ms 16048 KB Output is correct
7 Correct 305 ms 33048 KB Output is correct
8 Correct 291 ms 34364 KB Output is correct
9 Correct 277 ms 31644 KB Output is correct
10 Correct 170 ms 25376 KB Output is correct
11 Correct 199 ms 25328 KB Output is correct
12 Correct 80 ms 13548 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 325 ms 34568 KB Output is correct
2 Correct 302 ms 34576 KB Output is correct
3 Correct 333 ms 34504 KB Output is correct
4 Correct 215 ms 28048 KB Output is correct
5 Correct 189 ms 26112 KB Output is correct
6 Correct 94 ms 16048 KB Output is correct
7 Correct 305 ms 33048 KB Output is correct
8 Correct 291 ms 34364 KB Output is correct
9 Correct 277 ms 31644 KB Output is correct
10 Correct 170 ms 25376 KB Output is correct
11 Correct 199 ms 25328 KB Output is correct
12 Correct 80 ms 13548 KB Output is correct
13 Correct 359 ms 34028 KB Output is correct
14 Correct 373 ms 36572 KB Output is correct
15 Correct 334 ms 36184 KB Output is correct
16 Correct 259 ms 27652 KB Output is correct
17 Correct 240 ms 27564 KB Output is correct
18 Correct 108 ms 15992 KB Output is correct
19 Correct 357 ms 34000 KB Output is correct
20 Correct 357 ms 34312 KB Output is correct
21 Correct 359 ms 31924 KB Output is correct
22 Correct 173 ms 27208 KB Output is correct
23 Correct 194 ms 25352 KB Output is correct
24 Correct 79 ms 13764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6488 KB Output is correct
2 Correct 1 ms 6492 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 10980 KB Output is correct
8 Correct 14 ms 10844 KB Output is correct
9 Correct 13 ms 10844 KB Output is correct
10 Correct 9 ms 8028 KB Output is correct
11 Correct 8 ms 8112 KB Output is correct
12 Correct 4 ms 8792 KB Output is correct
13 Correct 12 ms 12548 KB Output is correct
14 Correct 12 ms 10844 KB Output is correct
15 Correct 14 ms 12636 KB Output is correct
16 Correct 7 ms 7560 KB Output is correct
17 Correct 8 ms 7516 KB Output is correct
18 Correct 3 ms 6748 KB Output is correct
19 Correct 325 ms 34568 KB Output is correct
20 Correct 302 ms 34576 KB Output is correct
21 Correct 333 ms 34504 KB Output is correct
22 Correct 215 ms 28048 KB Output is correct
23 Correct 189 ms 26112 KB Output is correct
24 Correct 94 ms 16048 KB Output is correct
25 Correct 305 ms 33048 KB Output is correct
26 Correct 291 ms 34364 KB Output is correct
27 Correct 277 ms 31644 KB Output is correct
28 Correct 170 ms 25376 KB Output is correct
29 Correct 199 ms 25328 KB Output is correct
30 Correct 80 ms 13548 KB Output is correct
31 Correct 359 ms 34028 KB Output is correct
32 Correct 373 ms 36572 KB Output is correct
33 Correct 334 ms 36184 KB Output is correct
34 Correct 259 ms 27652 KB Output is correct
35 Correct 240 ms 27564 KB Output is correct
36 Correct 108 ms 15992 KB Output is correct
37 Correct 357 ms 34000 KB Output is correct
38 Correct 357 ms 34312 KB Output is correct
39 Correct 359 ms 31924 KB Output is correct
40 Correct 173 ms 27208 KB Output is correct
41 Correct 194 ms 25352 KB Output is correct
42 Correct 79 ms 13764 KB Output is correct
43 Incorrect 940 ms 84244 KB Output isn't correct
44 Halted 0 ms 0 KB -