Submission #394424

# Submission time Handle Problem Language Result Execution time Memory
394424 2021-04-26T14:42:22 Z cpp219 Examination (JOI19_examination) C++14
100 / 100
1458 ms 86712 KB
#pragma GCC optimization "Ofast"
#pragma GCC optimization "unroll-loop"
#pragma GCC target ("avx2")

#include<bits/stdc++.h>
#define ll int
#define ld long double
#define fs first
#define sc second
using namespace std;
typedef pair<ll,ll> LL;
const ll N = 5e5 + 9;
const ll inf = 1e9 + 7;
vector<ll> v,node[N],bit[N];
struct student{
    ll A,B,AB;
};
student a[N];
bool lf (student a,student b){
    return a.AB < b.AB;
}
struct Query{
    ll X,Y,Z,id;
};
Query q[N];
bool lf2(Query a,Query b){
    return a.Z < b.Z;
}

ll n,Q,ans[N];

ll Search(ll x){
    return lower_bound(v.begin(),v.end(),x) - v.begin() + 1;
}

void compress(){
    sort(v.begin(),v.end()); v.resize(unique(v.begin(),v.end()) - v.begin());
    for (ll i = 1;i <= n;i++) a[i].A = Search(a[i].A),a[i].B = Search(a[i].B);
    for (ll i = 1;i <= Q;i++) q[i].X = Search(q[i].X),q[i].Y = Search(q[i].Y);
}

void fakeupd(ll x,ll y){
    for (ll i = x;i < N;i += i & -i) node[i].push_back(y);
}

void fakeget(ll x,ll y){
    for (ll i = x;i > 0;i -= i & -i) node[i].push_back(y);
}
ll Find(ll id,ll x){
    return lower_bound(node[id].begin(),node[id].end(),x) - node[id].begin() + 1;
}

void upd(ll x,ll y){
    for (ll i = x;i < N;i += i & -i)
        for (ll j = Find(i,y);j <= node[i].size();j += j & -j) bit[i][j]++;
}

ll Get(ll x,ll y){
    ll res = 0;
    for (ll i = x;i > 0;i -= i & -i)
        for (ll j = Find(i,y);j > 0;j -= j & -j) res += bit[i][j];
    return res;
}

ll cal(ll x,ll y){
    return Get(N - 1,N - 1) - Get(N - 1,y - 1) - Get(x - 1,N - 1) + Get(x - 1,y - 1);
}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #define task "test"
    if (fopen(task".INP","r")){
        freopen(task".INP","r",stdin);
        //freopen(task".OUT","w",stdout);
    }
    cin>>n>>Q;
    for (ll i = 1;i <= n;i++){
        cin>>a[i].A>>a[i].B; v.push_back(a[i].A); v.push_back(a[i].B);
        a[i].AB = a[i].A + a[i].B;
    }
    sort(a + 1,a + n + 1,lf);
    for (ll i = 1;i <= Q;i++){
        cin>>q[i].X>>q[i].Y>>q[i].Z,q[i].id = i;
        v.push_back(q[i].X); v.push_back(q[i].Y);
    }
    sort(q + 1,q + Q + 1,lf2); compress();
    //for (ll i = 1;i <= 1;i++) cout<<q[i].X<<" "<<q[i].Y<<" "<<q[i].Z<<"\n"; return 0;
    for (ll i = 1;i <= n;i++) fakeupd(a[i].A,a[i].B); fakeget(N - 1,N - 1);
    for (ll i = 1;i <= Q;i++){
        fakeget(q[i].X - 1,q[i].Y - 1); fakeget(q[i].X - 1,N - 1);
        fakeget(N - 1,q[i].Y - 1);
    }
    for (ll i = 1;i < N;i++){
        node[i].push_back(inf); sort(node[i].begin(),node[i].end());
        node[i].resize(unique(node[i].begin(),node[i].end()) - node[i].begin());
        bit[i].resize(node[i].size() + 3);
    }
    ll cur = n;
    for (ll i = Q;i >= 1;i--){
        while(cur && a[cur].AB >= q[i].Z) upd(a[cur].A,a[cur].B),cur--;
        ans[q[i].id] = cal(q[i].X,q[i].Y);
    }
    for (ll i = 1;i <= Q;i++) cout<<ans[i]<<"\n";
}

Compilation message

examination.cpp:1: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
    1 | #pragma GCC optimization "Ofast"
      | 
examination.cpp:2: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
    2 | #pragma GCC optimization "unroll-loop"
      | 
examination.cpp: In function 'void upd(int, int)':
examination.cpp:55:33: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |         for (ll j = Find(i,y);j <= node[i].size();j += j & -j) bit[i][j]++;
      |                               ~~^~~~~~~~~~~~~~~~~
examination.cpp: In function 'int main()':
examination.cpp:88:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   88 |     for (ll i = 1;i <= n;i++) fakeupd(a[i].A,a[i].B); fakeget(N - 1,N - 1);
      |     ^~~
examination.cpp:88:55: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   88 |     for (ll i = 1;i <= n;i++) fakeupd(a[i].A,a[i].B); fakeget(N - 1,N - 1);
      |                                                       ^~~~~~~
examination.cpp:73:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   73 |         freopen(task".INP","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 79 ms 55032 KB Output is correct
2 Correct 80 ms 55068 KB Output is correct
3 Correct 79 ms 55044 KB Output is correct
4 Correct 81 ms 55156 KB Output is correct
5 Correct 80 ms 55096 KB Output is correct
6 Correct 79 ms 55224 KB Output is correct
7 Correct 118 ms 56184 KB Output is correct
8 Correct 109 ms 56184 KB Output is correct
9 Correct 110 ms 56184 KB Output is correct
10 Correct 101 ms 55876 KB Output is correct
11 Correct 104 ms 56088 KB Output is correct
12 Correct 97 ms 55724 KB Output is correct
13 Correct 119 ms 56132 KB Output is correct
14 Correct 110 ms 56060 KB Output is correct
15 Correct 107 ms 56076 KB Output is correct
16 Correct 106 ms 56028 KB Output is correct
17 Correct 102 ms 55808 KB Output is correct
18 Correct 96 ms 55780 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1211 ms 84772 KB Output is correct
2 Correct 1193 ms 85432 KB Output is correct
3 Correct 1282 ms 85424 KB Output is correct
4 Correct 527 ms 77828 KB Output is correct
5 Correct 700 ms 80432 KB Output is correct
6 Correct 320 ms 73520 KB Output is correct
7 Correct 1036 ms 84548 KB Output is correct
8 Correct 1067 ms 83536 KB Output is correct
9 Correct 871 ms 82580 KB Output is correct
10 Correct 704 ms 79788 KB Output is correct
11 Correct 412 ms 76884 KB Output is correct
12 Correct 270 ms 73744 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1211 ms 84772 KB Output is correct
2 Correct 1193 ms 85432 KB Output is correct
3 Correct 1282 ms 85424 KB Output is correct
4 Correct 527 ms 77828 KB Output is correct
5 Correct 700 ms 80432 KB Output is correct
6 Correct 320 ms 73520 KB Output is correct
7 Correct 1036 ms 84548 KB Output is correct
8 Correct 1067 ms 83536 KB Output is correct
9 Correct 871 ms 82580 KB Output is correct
10 Correct 704 ms 79788 KB Output is correct
11 Correct 412 ms 76884 KB Output is correct
12 Correct 270 ms 73744 KB Output is correct
13 Correct 1264 ms 85528 KB Output is correct
14 Correct 1251 ms 85408 KB Output is correct
15 Correct 1192 ms 85448 KB Output is correct
16 Correct 521 ms 77940 KB Output is correct
17 Correct 762 ms 80284 KB Output is correct
18 Correct 317 ms 73580 KB Output is correct
19 Correct 1292 ms 85604 KB Output is correct
20 Correct 1263 ms 85552 KB Output is correct
21 Correct 1214 ms 85536 KB Output is correct
22 Correct 696 ms 79804 KB Output is correct
23 Correct 402 ms 76904 KB Output is correct
24 Correct 264 ms 73608 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 79 ms 55032 KB Output is correct
2 Correct 80 ms 55068 KB Output is correct
3 Correct 79 ms 55044 KB Output is correct
4 Correct 81 ms 55156 KB Output is correct
5 Correct 80 ms 55096 KB Output is correct
6 Correct 79 ms 55224 KB Output is correct
7 Correct 118 ms 56184 KB Output is correct
8 Correct 109 ms 56184 KB Output is correct
9 Correct 110 ms 56184 KB Output is correct
10 Correct 101 ms 55876 KB Output is correct
11 Correct 104 ms 56088 KB Output is correct
12 Correct 97 ms 55724 KB Output is correct
13 Correct 119 ms 56132 KB Output is correct
14 Correct 110 ms 56060 KB Output is correct
15 Correct 107 ms 56076 KB Output is correct
16 Correct 106 ms 56028 KB Output is correct
17 Correct 102 ms 55808 KB Output is correct
18 Correct 96 ms 55780 KB Output is correct
19 Correct 1211 ms 84772 KB Output is correct
20 Correct 1193 ms 85432 KB Output is correct
21 Correct 1282 ms 85424 KB Output is correct
22 Correct 527 ms 77828 KB Output is correct
23 Correct 700 ms 80432 KB Output is correct
24 Correct 320 ms 73520 KB Output is correct
25 Correct 1036 ms 84548 KB Output is correct
26 Correct 1067 ms 83536 KB Output is correct
27 Correct 871 ms 82580 KB Output is correct
28 Correct 704 ms 79788 KB Output is correct
29 Correct 412 ms 76884 KB Output is correct
30 Correct 270 ms 73744 KB Output is correct
31 Correct 1264 ms 85528 KB Output is correct
32 Correct 1251 ms 85408 KB Output is correct
33 Correct 1192 ms 85448 KB Output is correct
34 Correct 521 ms 77940 KB Output is correct
35 Correct 762 ms 80284 KB Output is correct
36 Correct 317 ms 73580 KB Output is correct
37 Correct 1292 ms 85604 KB Output is correct
38 Correct 1263 ms 85552 KB Output is correct
39 Correct 1214 ms 85536 KB Output is correct
40 Correct 696 ms 79804 KB Output is correct
41 Correct 402 ms 76904 KB Output is correct
42 Correct 264 ms 73608 KB Output is correct
43 Correct 1446 ms 86236 KB Output is correct
44 Correct 1458 ms 85928 KB Output is correct
45 Correct 1434 ms 85944 KB Output is correct
46 Correct 572 ms 78024 KB Output is correct
47 Correct 815 ms 83640 KB Output is correct
48 Correct 315 ms 72960 KB Output is correct
49 Correct 1286 ms 84560 KB Output is correct
50 Correct 1442 ms 86712 KB Output is correct
51 Correct 1304 ms 84856 KB Output is correct
52 Correct 840 ms 83436 KB Output is correct
53 Correct 464 ms 76952 KB Output is correct