Submission #369687

# Submission time Handle Problem Language Result Execution time Memory
369687 2021-02-22T08:13:35 Z azberjibiou Examination (JOI19_examination) C++17
100 / 100
506 ms 16272 KB
#include <bits/stdc++.h>
#define gibon ios::sync_with_stdio(false); cin.tie(0);
using namespace std;
#define fir first
#define sec second
#define ll long long
#define pii pair<int, int>
const int mxN=103000;
typedef struct pro{
    ll a, b, c;
}pro;
typedef struct qry{
    int x, sy, ey, idx, typ;
}qry;
int N, Q;
pro T[mxN];
pii A[mxN];
vector <int> coorx, coory, coorxy;
vector <int> xy;
int ans[mxN];
vector <qry> v;
vector <pii> swp;
int X, Y;
int seg[4*mxN];
bool cmp1(qry p, qry q)
{
    return p.x<q.x;
}
bool cmp2(pii a, pii b)
{
    return a.fir<b.fir;
}
void init(int idx, int s, int e)
{
    seg[idx]=0;
    if(s==e)    return;
    int mid=(s+e)/2;
    init(2*idx, s, mid);
    init(2*idx+1, mid+1, e);
}
int solv(int idx, int s1, int e1, int s2, int e2)
{
    if(s2>e1 || s1>e2)  return 0;
    if(s2<=s1 && e1<=e2)    return seg[idx];
    int mid=(s1+e1)/2;
    return solv(2*idx, s1, mid, s2, e2)+solv(2*idx+1, mid+1, e1, s2, e2);
}
void upd(int idx, int s, int e, int pos)
{
    if(pos<s || pos>e)  return;
    seg[idx]++;
    if(s==e)    return;
    int mid=(s+e)/2;
    upd(2*idx, s, mid, pos);
    upd(2*idx+1, mid+1, e, pos);
}
void make_coor()
{
    for(int i=0;i<N;i++)   coorx.push_back(A[i].fir), coory.push_back(A[i].sec);
    for(int i=0;i<N;i++)   coorxy.push_back(A[i].fir+A[i].sec);
    coorx.push_back(1000000007);
    coory.push_back(1000000007);
    coorx.push_back(-2);
    coory.push_back(-2);
    coorxy.push_back(2000000007);
    coorxy.push_back(-2);
    sort(coorx.begin(), coorx.end());   sort(coory.begin(), coory.end());
    sort(coorxy.begin(), coorxy.end());
    coorx.erase(unique(coorx.begin(), coorx.end()), coorx.end());
    coory.erase(unique(coory.begin(), coory.end()), coory.end());
    coorxy.erase(unique(coorxy.begin(), coorxy.end()), coorxy.end());
    X=coorx.size(), Y=coory.size();
}
int main()
{
    gibon
    cin >> N >> Q;
    for(int i=0;i<N;i++)    cin >> A[i].fir >> A[i].sec;
    for(int i=0;i<Q;i++)    cin >> T[i].a >> T[i].b >> T[i].c;
    make_coor();
    for(int i=0;i<Q;i++)
    {
        int nx=lower_bound(coorx.begin(), coorx.end(), T[i].a)-coorx.begin();
        int ny=lower_bound(coory.begin(), coory.end(), T[i].b)-coory.begin();
        //printf("i=%d, nx=%d, ny=%d\n", i, nx, ny);
        v.push_back({X-1, ny, Y-1, i, 1});
        v.push_back({nx-1, ny, Y-1, i, -1});
        if(T[i].a+T[i].b>=T[i].c)   continue;
        v.push_back({nx-1, 0, ny-1, i, -1});
    }
    sort(v.begin(), v.end(), cmp1);
    init(1, 0, Y-1);
    for(int i=0;i<N;i++)
    {
        int nx=lower_bound(coorx.begin(), coorx.end(), A[i].fir)-coorx.begin();
        int ny=lower_bound(coory.begin(), coory.end(), A[i].sec)-coory.begin();
        swp.push_back({nx, ny});
    }
    sort(swp.begin(), swp.end(), cmp2);
    //for(qry ele : v)    printf("ele=%d, %d, %d, %d, %d\n", ele.x, ele.sy, ele.ey, ele.idx, ele.typ);
    int cur=0;
    for(int i=0;i<N;i++)
    {
        while(cur!=v.size() && v[cur].x<swp[i].fir)
        {
            ans[v[cur].idx]+=solv(1, 0, Y-1, v[cur].sy, v[cur].ey)*v[cur].typ;
            cur++;
        }
        upd(1, 0, Y-1, swp[i].sec);
    }
    while(cur!=v.size())
    {
        ans[v[cur].idx]+=solv(1, 0, Y-1, v[cur].sy, v[cur].ey)*v[cur].typ;
        cur++;
    }
    //for(int i=0;i<Q;i++)    printf("ans[%d]=%d\n", i, ans[i]);
    ///-------------------------
    v.clear();
    for(int i=0;i<Q;i++)
    {
        if(T[i].a+T[i].b>=T[i].c)   continue;
        int ny=lower_bound(coory.begin(), coory.end(), T[i].b)-coory.begin();
        int nxy=lower_bound(coorxy.begin(), coorxy.end(), T[i].c)-coorxy.begin()-1;
        v.push_back({nxy, ny, Y-1, i, -1});
    }
    sort(v.begin(), v.end(), cmp1);
    swp.clear();
    for(int i=0;i<N;i++)
    {
        int nxy=lower_bound(coorxy.begin(), coorxy.end(), A[i].fir+A[i].sec)-coorxy.begin();
        int ny=lower_bound(coory.begin(), coory.end(), A[i].sec)-coory.begin();
        swp.push_back({nxy, ny});
    }
    sort(swp.begin(), swp.end(), cmp2);
    init(1, 0, Y-1);
    cur=0;
    for(int i=0;i<N;i++)
    {
        while(cur!=v.size() && v[cur].x<swp[i].fir)
        {
            ans[v[cur].idx]+=solv(1, 0, Y-1, v[cur].sy, v[cur].ey)*v[cur].typ;
            cur++;
        }
        upd(1, 0, Y-1, swp[i].sec);
    }
    while(cur!=v.size())
    {
        ans[v[cur].idx]+=solv(1, 0, Y-1, v[cur].sy, v[cur].ey)*v[cur].typ;
        cur++;
    }
    //for(int i=0;i<Q;i++)    printf("ans[%d]=%d\n", i, ans[i]);
    ///--------------------------
    v.clear();
    for(int i=0;i<Q;i++)
    {
        if(T[i].a+T[i].b>=T[i].c)   continue;
        int nxy=lower_bound(coorxy.begin(), coorxy.end(), T[i].c)-coorxy.begin()-1;
        int nx=lower_bound(coorx.begin(), coorx.end(), T[i].a)-coorx.begin();
        v.push_back({nxy, nx, X-1, i, -1});
    }
    sort(v.begin(), v.end(), cmp1);
    swp.clear();
    for(int i=0;i<N;i++)
    {
        int nxy=lower_bound(coorxy.begin(), coorxy.end(), A[i].fir+A[i].sec)-coorxy.begin();
        int nx=lower_bound(coorx.begin(), coorx.end(), A[i].fir)-coorx.begin();
        swp.push_back({nxy, nx});
    }
    sort(swp.begin(), swp.end(), cmp2);
    init(1, 0, X-1);
    cur=0;
    for(int i=0;i<N;i++)
    {
        while(cur!=v.size() && v[cur].x<swp[i].fir)
        {
            ans[v[cur].idx]+=solv(1, 0, X-1, v[cur].sy, v[cur].ey)*v[cur].typ;
            cur++;
        }
        upd(1, 0, X-1, swp[i].sec);
    }
    while(cur!=v.size())
    {
        ans[v[cur].idx]+=solv(1, 0, X-1, v[cur].sy, v[cur].ey)*v[cur].typ;
        cur++;
    }
    //for(int i=0;i<Q;i++)    printf("ans[%d]=%d\n", i, ans[i]);
    ///-------------------

    for(int i=0;i<N;i++)    xy.push_back(A[i].fir+A[i].sec);
    sort(xy.begin(), xy.end());
    for(int i=0;i<Q;i++)
    {
        if(T[i].a+T[i].b>=T[i].c)   continue;
        ans[i]+=lower_bound(xy.begin(), xy.end(), T[i].c)-xy.begin();
    }
    for(int i=0;i<Q;i++)    cout << ans[i] << '\n';
}

Compilation message

examination.cpp: In function 'int main()':
examination.cpp:104:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<qry>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  104 |         while(cur!=v.size() && v[cur].x<swp[i].fir)
      |               ~~~^~~~~~~~~~
examination.cpp:111:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<qry>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  111 |     while(cur!=v.size())
      |           ~~~^~~~~~~~~~
examination.cpp:139:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<qry>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  139 |         while(cur!=v.size() && v[cur].x<swp[i].fir)
      |               ~~~^~~~~~~~~~
examination.cpp:146:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<qry>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  146 |     while(cur!=v.size())
      |           ~~~^~~~~~~~~~
examination.cpp:174:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<qry>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  174 |         while(cur!=v.size() && v[cur].x<swp[i].fir)
      |               ~~~^~~~~~~~~~
examination.cpp:181:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<qry>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  181 |     while(cur!=v.size())
      |           ~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 11 ms 992 KB Output is correct
8 Correct 11 ms 992 KB Output is correct
9 Correct 11 ms 992 KB Output is correct
10 Correct 8 ms 992 KB Output is correct
11 Correct 9 ms 992 KB Output is correct
12 Correct 7 ms 864 KB Output is correct
13 Correct 9 ms 1140 KB Output is correct
14 Correct 10 ms 992 KB Output is correct
15 Correct 9 ms 992 KB Output is correct
16 Correct 7 ms 876 KB Output is correct
17 Correct 8 ms 992 KB Output is correct
18 Correct 3 ms 864 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 359 ms 12812 KB Output is correct
2 Correct 339 ms 12840 KB Output is correct
3 Correct 338 ms 12812 KB Output is correct
4 Correct 254 ms 12812 KB Output is correct
5 Correct 269 ms 12940 KB Output is correct
6 Correct 139 ms 12300 KB Output is correct
7 Correct 336 ms 12808 KB Output is correct
8 Correct 342 ms 12812 KB Output is correct
9 Correct 329 ms 12940 KB Output is correct
10 Correct 275 ms 12684 KB Output is correct
11 Correct 227 ms 12684 KB Output is correct
12 Correct 99 ms 12044 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 359 ms 12812 KB Output is correct
2 Correct 339 ms 12840 KB Output is correct
3 Correct 338 ms 12812 KB Output is correct
4 Correct 254 ms 12812 KB Output is correct
5 Correct 269 ms 12940 KB Output is correct
6 Correct 139 ms 12300 KB Output is correct
7 Correct 336 ms 12808 KB Output is correct
8 Correct 342 ms 12812 KB Output is correct
9 Correct 329 ms 12940 KB Output is correct
10 Correct 275 ms 12684 KB Output is correct
11 Correct 227 ms 12684 KB Output is correct
12 Correct 99 ms 12044 KB Output is correct
13 Correct 463 ms 13708 KB Output is correct
14 Correct 374 ms 13196 KB Output is correct
15 Correct 347 ms 12812 KB Output is correct
16 Correct 316 ms 13708 KB Output is correct
17 Correct 346 ms 13708 KB Output is correct
18 Correct 152 ms 12556 KB Output is correct
19 Correct 440 ms 13836 KB Output is correct
20 Correct 405 ms 13452 KB Output is correct
21 Correct 473 ms 16272 KB Output is correct
22 Correct 274 ms 12684 KB Output is correct
23 Correct 224 ms 12556 KB Output is correct
24 Correct 98 ms 11916 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 11 ms 992 KB Output is correct
8 Correct 11 ms 992 KB Output is correct
9 Correct 11 ms 992 KB Output is correct
10 Correct 8 ms 992 KB Output is correct
11 Correct 9 ms 992 KB Output is correct
12 Correct 7 ms 864 KB Output is correct
13 Correct 9 ms 1140 KB Output is correct
14 Correct 10 ms 992 KB Output is correct
15 Correct 9 ms 992 KB Output is correct
16 Correct 7 ms 876 KB Output is correct
17 Correct 8 ms 992 KB Output is correct
18 Correct 3 ms 864 KB Output is correct
19 Correct 359 ms 12812 KB Output is correct
20 Correct 339 ms 12840 KB Output is correct
21 Correct 338 ms 12812 KB Output is correct
22 Correct 254 ms 12812 KB Output is correct
23 Correct 269 ms 12940 KB Output is correct
24 Correct 139 ms 12300 KB Output is correct
25 Correct 336 ms 12808 KB Output is correct
26 Correct 342 ms 12812 KB Output is correct
27 Correct 329 ms 12940 KB Output is correct
28 Correct 275 ms 12684 KB Output is correct
29 Correct 227 ms 12684 KB Output is correct
30 Correct 99 ms 12044 KB Output is correct
31 Correct 463 ms 13708 KB Output is correct
32 Correct 374 ms 13196 KB Output is correct
33 Correct 347 ms 12812 KB Output is correct
34 Correct 316 ms 13708 KB Output is correct
35 Correct 346 ms 13708 KB Output is correct
36 Correct 152 ms 12556 KB Output is correct
37 Correct 440 ms 13836 KB Output is correct
38 Correct 405 ms 13452 KB Output is correct
39 Correct 473 ms 16272 KB Output is correct
40 Correct 274 ms 12684 KB Output is correct
41 Correct 224 ms 12556 KB Output is correct
42 Correct 98 ms 11916 KB Output is correct
43 Correct 463 ms 13708 KB Output is correct
44 Correct 468 ms 13836 KB Output is correct
45 Correct 398 ms 13196 KB Output is correct
46 Correct 328 ms 14348 KB Output is correct
47 Correct 361 ms 14348 KB Output is correct
48 Correct 193 ms 16144 KB Output is correct
49 Correct 444 ms 13964 KB Output is correct
50 Correct 506 ms 15760 KB Output is correct
51 Correct 498 ms 15632 KB Output is correct
52 Correct 365 ms 14220 KB Output is correct
53 Correct 252 ms 13068 KB Output is correct