Submission #365337

# Submission time Handle Problem Language Result Execution time Memory
365337 2021-02-11T13:32:51 Z mat_v Examination (JOI19_examination) C++14
0 / 100
341 ms 15832 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>

#define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
#define fb(i,a,b) for(int (i) = (a); (i) >= (b); --(i))
#define mod 998244353
#define xx first
#define yy second
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define ll long long
#define pii pair<int,int>
#define N 100005

using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>,rb_tree_tag, tree_order_statistics_node_update> ordered_set;/// find_by_order(x)(x+1th) , order_of_key() (strictly less)
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());


int n,q;
pii niz[N];
struct upit{
    int x,y,z;
    int idx;
}kv[N];



map<int, int>slika;

bool cmp(pii a, pii b){
    return a.xx > b.xx;
}

int ans[N];
int br;
int bit[6 * N][2];
void dodaj(int x, int idx){
    for(;x > 0; x-=(x&-x))bit[x][idx]++;
}
int query(int x, int idx){
    int sol = 0;
    for(;x <= 6 * n; x+=(x&-x))sol += bit[x][idx];
    return sol;
}

struct fw{
    int idx;
    int poz;
    int znk;
    int val;
    int zakoju;
};

bool cmp2(fw a, fw b){
    return a.poz < b.poz;
}

int dokle(int x){
    if(x > niz[1].xx)return 0;
    if(x <= niz[n].xx)return n;
    int l = 1;
    int r = n;
    while(l < r){
        int mid = (l + r + 1) / 2;
        if(niz[mid].xx >= x)l = mid;
        else r = mid - 1;
    }
    return l;
}


vector<fw> v;

int main()
{

    ios_base::sync_with_stdio(false); cin.tie(0);
    vector<int> svi;

    cin >> n >> q;
    ff(i,1,n){
        cin >> niz[i].xx >> niz[i].yy;
        svi.pb(niz[i].xx);
        svi.pb(niz[i].yy);
        svi.pb(niz[i].xx + niz[i].yy);
    }
    sort(niz + 1, niz + n + 1, cmp);
    ff(i,1,q){
        int a,b,c;
        cin >> a >> b >> c;
        int prvi = dokle(a);
        int drugi = dokle(c - b);
        if(c - b <= a){
            v.pb({0,prvi,1,b,i});
        }
        else{
            assert(false);
            v.pb({0,drugi,1,b,i});
            if(drugi < prvi){
                v.pb({1,drugi,-1,c,i});
                v.pb({1,prvi,1,c,i});
            }
        }
        kv[i].x = a;
        kv[i].y = b;
        kv[i].z = c;
        svi.pb(a);
        svi.pb(b);
        svi.pb(c);
    }
    sort(svi.begin(), svi.end());
    int last = -1;
    for(auto c:svi){
        if(c == last)continue;
        br++;
        slika[c] = br;
        last = c;
    }

    sort(v.begin(), v.end(), cmp2);

    int tr = 0;
    ff(i,1,n){
        dodaj(slika[niz[i].yy], 0);
        dodaj(slika[niz[i].xx + niz[i].yy], 1);
        while(1){
            int sta = v.size();
            if(tr == sta)break;
            if(v[tr].poz > i)break;
            ans[v[tr].zakoju] += (v[tr].znk)*query(slika[v[tr].val],v[tr].idx);
            tr++;
        }
    }
    ff(i,1,q)cout << ans[i] << "\n";


    return 0;
}
/*
5 1
35 100
70 70
45 15
80 40
20 95
20 50 120



*/

Compilation message

examination.cpp: In function 'int main()':
examination.cpp:6:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    6 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
examination.cpp:85:5: note: in expansion of macro 'ff'
   85 |     ff(i,1,n){
      |     ^~
examination.cpp:6:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    6 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
examination.cpp:92:5: note: in expansion of macro 'ff'
   92 |     ff(i,1,q){
      |     ^~
examination.cpp:6:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    6 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
examination.cpp:127:5: note: in expansion of macro 'ff'
  127 |     ff(i,1,n){
      |     ^~
examination.cpp:6:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    6 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
examination.cpp:138:5: note: in expansion of macro 'ff'
  138 |     ff(i,1,q)cout << ans[i] << "\n";
      |     ^~
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 492 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 314 ms 15832 KB Output is correct
2 Correct 318 ms 15576 KB Output is correct
3 Correct 341 ms 15576 KB Output is correct
4 Correct 186 ms 13412 KB Output is correct
5 Correct 224 ms 13536 KB Output is correct
6 Correct 100 ms 9588 KB Output is correct
7 Correct 291 ms 15448 KB Output is correct
8 Correct 298 ms 15448 KB Output is correct
9 Correct 288 ms 15320 KB Output is correct
10 Incorrect 197 ms 12760 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 314 ms 15832 KB Output is correct
2 Correct 318 ms 15576 KB Output is correct
3 Correct 341 ms 15576 KB Output is correct
4 Correct 186 ms 13412 KB Output is correct
5 Correct 224 ms 13536 KB Output is correct
6 Correct 100 ms 9588 KB Output is correct
7 Correct 291 ms 15448 KB Output is correct
8 Correct 298 ms 15448 KB Output is correct
9 Correct 288 ms 15320 KB Output is correct
10 Incorrect 197 ms 12760 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 492 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -