Submission #477807

# Submission time Handle Problem Language Result Execution time Memory
477807 2021-10-04T00:21:08 Z Rainbowbunny Examination (JOI19_examination) C++17
100 / 100
722 ms 54340 KB
#include <bits/stdc++.h>
using namespace std;
 
const int MAXN = 2e5 + 5;
 
struct Data
{
    int s, t, sum, id;
    Data(int s = 0, int t = 0, int sum = 0, int id = 0) : s(s), t(t), sum(sum), id(id) {}
};
 
int n, q;
int ans[MAXN];
vector <int> S, T;
vector <int> Value[MAXN], BIT[MAXN];
vector <Data> Student, Query, Query2D;
 
void Unique(vector <int> &A)
{
    sort(A.begin(), A.end());
    A.erase(unique(A.begin(), A.end()), A.end());
}
 
void Change(vector <Data> &A)
{
    for(auto &x : A)
    {
        x.s = S.end() - lower_bound(S.begin(), S.end(), x.s);
        x.t = T.end() - lower_bound(T.begin(), T.end(), x.t);
    }
}
 
int GetPos(vector <int> &A, int b)
{
    return lower_bound(A.begin(), A.end(), b) - A.begin();
}
 
void FakeUpdate(int x, int y)
{
    for(x; x < MAXN; x += x & -x)
    {
        Value[x].push_back(y);
    }
}
 
void FakeGet(int x, int y)
{
    for(x; x > 0; x -= x & -x)
    {
        Value[x].push_back(y);
    }
}
 
void Update(int x, int y)
{
    for(x; x < MAXN; x += x & -x)
    {
        for(int id = GetPos(Value[x], y); id < (int)BIT[x].size(); id += id & -id)
        {
            BIT[x][id]++;
        }
    }
}
 
int Get(int x, int y)
{
    int ans = 0;
    for(x; x > 0; x -= x & -x)
    {
        for(int id = GetPos(Value[x], y); id > 0; id -= id & -id)
        {
            ans += BIT[x][id];
        }
    }
    return ans;
}
 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> q;
    Student.resize(n);
    for(int i = 0; i < n; i++)
    {
        cin >> Student[i].s >> Student[i].t;
        S.push_back(Student[i].s);
        T.push_back(Student[i].t);
        Student[i].sum = Student[i].s + Student[i].t;
        Student[i].id = -1;
    }
    Query.resize(q);
    for(int i = 0; i < q; i++)
    {
        cin >> Query[i].s >> Query[i].t >> Query[i].sum;
        S.push_back(Query[i].s);
        T.push_back(Query[i].t);
        Query[i].id = i;
    }
    sort(Student.begin(), Student.end(), [](Data A, Data B)
    {
        return A.sum > B.sum;
    });
    sort(Query.begin(), Query.end(), [](Data A, Data B)
    {
        return A.sum > B.sum;
    });
    Unique(S);
    Unique(T);
    Change(Student);
    Change(Query);
    int pt0 = 0, pt1 = 0;
    while(pt0 < (int)Student.size() and pt1 < (int)Query.size())
    {
        if(Student[pt0].sum >= Query[pt1].sum)
        {
            Query2D.push_back(Student[pt0]);
            pt0++;
        }
        else
        {
            Query2D.push_back(Query[pt1]);
            pt1++;
        }
    }
    while(pt1 < (int)Query.size())
    {
        Query2D.push_back(Query[pt1]);
        pt1++;
    }
    for(auto x : Query2D)
    {
        if(x.id == -1)
        {
            FakeUpdate(x.s, x.t);
        }
        else
        {
            FakeGet(x.s, x.t);
        }
    }
    for(int i = 1; i < MAXN; i++)
    {
        Value[i].push_back(0);
        Unique(Value[i]);
        BIT[i].resize(Value[i].size() + 5);
    }
    for(auto x : Query2D)
    {
        if(x.id == -1)
        {
            Update(x.s, x.t);
        }
        else
        {
            ans[x.id] = Get(x.s, x.t);
        }
    }
    for(int i = 0; i < q; i++)
    {
        cout << ans[i] << '\n';
    }
}

Compilation message

examination.cpp: In function 'void FakeUpdate(int, int)':
examination.cpp:40:9: warning: statement has no effect [-Wunused-value]
   40 |     for(x; x < MAXN; x += x & -x)
      |         ^
examination.cpp: In function 'void FakeGet(int, int)':
examination.cpp:48:9: warning: statement has no effect [-Wunused-value]
   48 |     for(x; x > 0; x -= x & -x)
      |         ^
examination.cpp: In function 'void Update(int, int)':
examination.cpp:56:9: warning: statement has no effect [-Wunused-value]
   56 |     for(x; x < MAXN; x += x & -x)
      |         ^
examination.cpp: In function 'int Get(int, int)':
examination.cpp:68:9: warning: statement has no effect [-Wunused-value]
   68 |     for(x; x > 0; x -= x & -x)
      |         ^
# Verdict Execution time Memory Grader output
1 Correct 30 ms 22180 KB Output is correct
2 Correct 28 ms 22220 KB Output is correct
3 Correct 29 ms 22220 KB Output is correct
4 Correct 28 ms 22212 KB Output is correct
5 Correct 29 ms 22208 KB Output is correct
6 Correct 28 ms 22184 KB Output is correct
7 Correct 45 ms 22932 KB Output is correct
8 Correct 44 ms 22980 KB Output is correct
9 Correct 44 ms 22980 KB Output is correct
10 Correct 43 ms 22772 KB Output is correct
11 Correct 53 ms 22964 KB Output is correct
12 Correct 37 ms 22684 KB Output is correct
13 Correct 44 ms 22912 KB Output is correct
14 Correct 44 ms 23064 KB Output is correct
15 Correct 43 ms 22928 KB Output is correct
16 Correct 40 ms 22952 KB Output is correct
17 Correct 54 ms 22840 KB Output is correct
18 Correct 40 ms 22812 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 660 ms 47104 KB Output is correct
2 Correct 595 ms 47012 KB Output is correct
3 Correct 608 ms 47308 KB Output is correct
4 Correct 281 ms 41960 KB Output is correct
5 Correct 429 ms 44180 KB Output is correct
6 Correct 195 ms 39580 KB Output is correct
7 Correct 604 ms 46688 KB Output is correct
8 Correct 617 ms 47128 KB Output is correct
9 Correct 607 ms 45800 KB Output is correct
10 Correct 372 ms 43288 KB Output is correct
11 Correct 230 ms 41224 KB Output is correct
12 Correct 151 ms 38600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 660 ms 47104 KB Output is correct
2 Correct 595 ms 47012 KB Output is correct
3 Correct 608 ms 47308 KB Output is correct
4 Correct 281 ms 41960 KB Output is correct
5 Correct 429 ms 44180 KB Output is correct
6 Correct 195 ms 39580 KB Output is correct
7 Correct 604 ms 46688 KB Output is correct
8 Correct 617 ms 47128 KB Output is correct
9 Correct 607 ms 45800 KB Output is correct
10 Correct 372 ms 43288 KB Output is correct
11 Correct 230 ms 41224 KB Output is correct
12 Correct 151 ms 38600 KB Output is correct
13 Correct 625 ms 47132 KB Output is correct
14 Correct 654 ms 47124 KB Output is correct
15 Correct 659 ms 47236 KB Output is correct
16 Correct 299 ms 41892 KB Output is correct
17 Correct 442 ms 44492 KB Output is correct
18 Correct 189 ms 39588 KB Output is correct
19 Correct 625 ms 47156 KB Output is correct
20 Correct 616 ms 47388 KB Output is correct
21 Correct 716 ms 45912 KB Output is correct
22 Correct 398 ms 43304 KB Output is correct
23 Correct 254 ms 41164 KB Output is correct
24 Correct 145 ms 38376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 22180 KB Output is correct
2 Correct 28 ms 22220 KB Output is correct
3 Correct 29 ms 22220 KB Output is correct
4 Correct 28 ms 22212 KB Output is correct
5 Correct 29 ms 22208 KB Output is correct
6 Correct 28 ms 22184 KB Output is correct
7 Correct 45 ms 22932 KB Output is correct
8 Correct 44 ms 22980 KB Output is correct
9 Correct 44 ms 22980 KB Output is correct
10 Correct 43 ms 22772 KB Output is correct
11 Correct 53 ms 22964 KB Output is correct
12 Correct 37 ms 22684 KB Output is correct
13 Correct 44 ms 22912 KB Output is correct
14 Correct 44 ms 23064 KB Output is correct
15 Correct 43 ms 22928 KB Output is correct
16 Correct 40 ms 22952 KB Output is correct
17 Correct 54 ms 22840 KB Output is correct
18 Correct 40 ms 22812 KB Output is correct
19 Correct 660 ms 47104 KB Output is correct
20 Correct 595 ms 47012 KB Output is correct
21 Correct 608 ms 47308 KB Output is correct
22 Correct 281 ms 41960 KB Output is correct
23 Correct 429 ms 44180 KB Output is correct
24 Correct 195 ms 39580 KB Output is correct
25 Correct 604 ms 46688 KB Output is correct
26 Correct 617 ms 47128 KB Output is correct
27 Correct 607 ms 45800 KB Output is correct
28 Correct 372 ms 43288 KB Output is correct
29 Correct 230 ms 41224 KB Output is correct
30 Correct 151 ms 38600 KB Output is correct
31 Correct 625 ms 47132 KB Output is correct
32 Correct 654 ms 47124 KB Output is correct
33 Correct 659 ms 47236 KB Output is correct
34 Correct 299 ms 41892 KB Output is correct
35 Correct 442 ms 44492 KB Output is correct
36 Correct 189 ms 39588 KB Output is correct
37 Correct 625 ms 47156 KB Output is correct
38 Correct 616 ms 47388 KB Output is correct
39 Correct 716 ms 45912 KB Output is correct
40 Correct 398 ms 43304 KB Output is correct
41 Correct 254 ms 41164 KB Output is correct
42 Correct 145 ms 38376 KB Output is correct
43 Correct 710 ms 47704 KB Output is correct
44 Correct 696 ms 52716 KB Output is correct
45 Correct 673 ms 52744 KB Output is correct
46 Correct 373 ms 46172 KB Output is correct
47 Correct 439 ms 50120 KB Output is correct
48 Correct 197 ms 40292 KB Output is correct
49 Correct 722 ms 54340 KB Output is correct
50 Correct 653 ms 52776 KB Output is correct
51 Correct 669 ms 54312 KB Output is correct
52 Correct 413 ms 49372 KB Output is correct
53 Correct 273 ms 44480 KB Output is correct