Submission #863972

# Submission time Handle Problem Language Result Execution time Memory
863972 2023-10-21T15:17:38 Z prohacker Examination (JOI19_examination) C++14
2 / 100
3000 ms 372712 KB
#include <bits/stdc++.h>
#define ll long long
#define ld long double

using namespace std;

const int N = 1e5+10;
const int INF = 1e9;
const int mod = 1e9+7;

int n,t,ans[N],mx;
map<pair<int,int>,int> bit;
pair<int,int> a[N];
struct Node{
    int l,r,all,id;
}q[N];

void update(int x, int y, int val) {
    while(x > 0) {
        int _y = y;
        while(_y > 0) {
            bit[{x,_y}] += val;
            _y -= (_y & (-_y));
        }
        x -= (x & (-x));
    }
}

int get(int x, int y) {
    int res = 0;
    while(x <= mx) {
        int _y = y;
        while(_y <= mx) {
            res += bit[{x,_y}];
            _y += (_y & (-_y));
        }
        x += (x & (-x));
    }
    return res;
}

signed main()
{
    if (fopen("Examination.inp", "r")) {
        freopen("Examination.inp", "r", stdin);
        freopen("Examination.out", "w", stdout);
    }
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> t;
    for(int i = 1 ; i <= n ; i++) {
        cin >> a[i].first >> a[i].second;
        a[i].first++;
        a[i].second++;
        mx = max(mx,a[i].first);
        mx = max(mx,a[i].second);
    }
    for(int i = 1 ; i <= t ; i++) {
        cin >> q[i].l >> q[i].r >> q[i].all;
        q[i].l++;
        q[i].r++;
        q[i].id = i;
        q[i].all += 2;
    }
    sort(q+1,q+t+1,[](Node u, Node v) {
        return u.all > v.all;
    });
    sort(a+1,a+n+1,[](pair<int,int> u, pair<int,int> v) {
        return u.first+u.second > v.first+v.second;
    });
    for(int i = 1,j = 1 ; i <= t ; i++) {
        while(j > 0 && a[j].first+a[j].second >= q[i].all) {
            update(a[j].first,a[j].second,1);
            j++;
        }
        ans[q[i].id] = get(q[i].l,q[i].r);
    }
    for(int i = 1 ; i <= t ; i++) {
        cout << ans[i] << '\n';
    }
    return 0;
}

Compilation message

examination.cpp: In function 'int main()':
examination.cpp:45:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   45 |         freopen("Examination.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
examination.cpp:46:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   46 |         freopen("Examination.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 247 ms 80436 KB Output is correct
8 Correct 247 ms 80272 KB Output is correct
9 Correct 248 ms 80468 KB Output is correct
10 Correct 185 ms 58028 KB Output is correct
11 Correct 273 ms 57980 KB Output is correct
12 Correct 2 ms 2396 KB Output is correct
13 Correct 252 ms 80824 KB Output is correct
14 Correct 247 ms 80724 KB Output is correct
15 Correct 247 ms 80124 KB Output is correct
16 Correct 258 ms 58020 KB Output is correct
17 Correct 189 ms 58448 KB Output is correct
18 Correct 1 ms 2392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 3067 ms 372712 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3067 ms 372712 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 247 ms 80436 KB Output is correct
8 Correct 247 ms 80272 KB Output is correct
9 Correct 248 ms 80468 KB Output is correct
10 Correct 185 ms 58028 KB Output is correct
11 Correct 273 ms 57980 KB Output is correct
12 Correct 2 ms 2396 KB Output is correct
13 Correct 252 ms 80824 KB Output is correct
14 Correct 247 ms 80724 KB Output is correct
15 Correct 247 ms 80124 KB Output is correct
16 Correct 258 ms 58020 KB Output is correct
17 Correct 189 ms 58448 KB Output is correct
18 Correct 1 ms 2392 KB Output is correct
19 Execution timed out 3067 ms 372712 KB Time limit exceeded
20 Halted 0 ms 0 KB -