답안 #747629

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
747629 2023-05-24T12:10:46 Z TahirAliyev Examination (JOI19_examination) C++17
0 / 100
14 ms 340 KB
#include <bits/stdc++.h>
 
#pragma GCC optimize("O3")
 
using namespace std;
 
#define ll long long int
#define oo 1e9
#define pii pair<int, int>

const int MAX = 1e5 + 5;
const int LOGMAX = 30;
const int treeSize = MAX * LOGMAX * LOGMAX;

int tree[treeSize];
int L[treeSize], R[treeSize];

int n, m;
int nxt = MAX * 4;

void update1d(int node, int l, int r, int pos, int val){
    tree[node] += val;
    if(l == r) return;
    int mid = (l + r) / 2;
    if(pos <= mid){
        if(!L[node]) L[node] = ++nxt;
        update1d(L[node], l, mid ,pos, val);
    }
    else{
        if(!R[node]) R[node] = ++nxt;
        update1d(R[node], mid + 1, r ,pos, val);
    }
}

int ask1d(int node, int l, int r, int ql, int qr){
    if(node == 0) return 0;
    if(r < ql || qr < l) return 0;
    if(ql <= l && r <= qr) return tree[node];
    int mid = (l + r) / 2;
    return ask1d(L[node], l, mid, ql, qr) + ask1d(R[node], mid + 1, r, ql, qr);
}

void update2d(int node, int l, int r, int posx, int posy, int val){
    update1d(node, 1, n, posx, val);
    if(l == r) return;
    int mid = (l + r) / 2;
    if(posy <= mid){
        update2d(2 * node, l, mid, posx, posy, val);
    }
    else{
        update2d(2 * node + 1, mid + 1, r, posx, posy, val);
    }
}

int ask2d(int node, int l, int r, int x1, int x2, int y1, int y2){
    if(r < y1 || y2 < l) return 0;
    if(y1 <= l && r <= y2) return ask1d(node, 1, n, x1, x2);
    int mid = (l + r) / 2;
    return ask2d(2 * node, l, mid, x1, x2, y1, y2) + ask2d(2 * node + 1, mid + 1, r, x1, x2, y1, y2);
}


bool comp(array<int, 4> a, array<int, 4> b){
    return (a[2] < b[2]);
}

bool comp2(pii a, pii b){
    return a.first + a.second  < b.first + b.second;
}

pii arr[MAX];
vector<int> v1, v2;
vector<array<int, 4>> q;

void INPUT(){
    cin >> n >> m; 
    for (int i = 0; i < n; i++)
    {
        scanf("%d%d", arr[i].first, arr[i].second);
        v1.push_back(arr[i].first);
        v2.push_back(arr[i].second);
    }
    sort(v1.begin(), v1.end());
    sort(v2.begin(), v2.end());
    for (int i = 0; i < m; i++)
    {
        int a, b, c; scanf("%d%d%d", a, b, c);
        q.push_back({a, b, c, i});
    }
    sort(q.begin(), q.end(), comp);
}

int main(){
    INPUT();
    for (int i = 0; i < n; i++)
    {
        int a = lower_bound(v1.begin(), v1.end(), arr[i].first) - v1.begin() + 1;
        int b = lower_bound(v2.begin(), v2.end(), arr[i].second) - v2.begin() + 1;
        update2d(1, 1, n, a, b, 1);
    }
    sort(arr, arr + n, comp2);
    int p = 0;
    int ans[m];
    for(array<int, 4> t : q){
        int X = lower_bound(v1.begin(), v1.end(), t[0]) - v1.begin() + 1;
        int Y = lower_bound(v2.begin(), v2.end(), t[1]) - v2.begin() + 1;
        while(t[2] > arr[p].first + arr[p].second){
            int a = lower_bound(v1.begin(), v1.end(), arr[p].first) - v1.begin() + 1;
            int b = lower_bound(v2.begin(), v2.end(), arr[p].second) - v2.begin() + 1;
            update2d(1, 1, n, a, b, -1);
            p++;
        }
        ans[t[3]] = ask2d(1, 1, n, X, n, Y, n);
    }
    for(int a: ans){
        cout << a << '\n';
    }
}

Compilation message

examination.cpp: In function 'void INPUT()':
examination.cpp:79:17: warning: format '%d' expects argument of type 'int*', but argument 2 has type 'int' [-Wformat=]
   79 |         scanf("%d%d", arr[i].first, arr[i].second);
      |                ~^     ~~~~~~~~~~~~
      |                 |            |
      |                 int*         int
examination.cpp:79:19: warning: format '%d' expects argument of type 'int*', but argument 3 has type 'int' [-Wformat=]
   79 |         scanf("%d%d", arr[i].first, arr[i].second);
      |                  ~^                 ~~~~~~~~~~~~~
      |                   |                        |
      |                   int*                     int
examination.cpp:87:30: warning: format '%d' expects argument of type 'int*', but argument 2 has type 'int' [-Wformat=]
   87 |         int a, b, c; scanf("%d%d%d", a, b, c);
      |                             ~^       ~
      |                              |       |
      |                              int*    int
examination.cpp:87:32: warning: format '%d' expects argument of type 'int*', but argument 3 has type 'int' [-Wformat=]
   87 |         int a, b, c; scanf("%d%d%d", a, b, c);
      |                               ~^        ~
      |                                |        |
      |                                int*     int
examination.cpp:87:34: warning: format '%d' expects argument of type 'int*', but argument 4 has type 'int' [-Wformat=]
   87 |         int a, b, c; scanf("%d%d%d", a, b, c);
      |                                 ~^         ~
      |                                  |         |
      |                                  int*      int
examination.cpp:79:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   79 |         scanf("%d%d", arr[i].first, arr[i].second);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
examination.cpp:87:27: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   87 |         int a, b, c; scanf("%d%d%d", a, b, c);
      |                      ~~~~~^~~~~~~~~~~~~~~~~~~
examination.cpp:87:27: warning: 'a' may be used uninitialized in this function [-Wmaybe-uninitialized]
   87 |         int a, b, c; scanf("%d%d%d", a, b, c);
      |                      ~~~~~^~~~~~~~~~~~~~~~~~~
examination.cpp:87:27: warning: 'b' may be used uninitialized in this function [-Wmaybe-uninitialized]
examination.cpp:87:27: warning: 'c' may be used uninitialized in this function [-Wmaybe-uninitialized]
# 결과 실행 시간 메모리 Grader output
1 Runtime error 14 ms 340 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 14 ms 340 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 14 ms 340 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 14 ms 340 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -