답안 #157184

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
157184 2019-10-10T02:41:26 Z souhhcong Examination (JOI19_examination) C++14
0 / 100
94 ms 17232 KB
#include <iostream>
#include <algorithm>
using namespace std;

const int N = 1e5+5, INF = 1e9+9;
struct query
{
    int x, y, s, id, type;
    bool operator < (const query &o) const
    {
        return x > o.x;
    }
};

int mn[8*N], sum[8*N];
int n, qu, ans[N];
query q[2*N];

void update_mn(int id, int l, int r, int pos, int val)
{
    if (l > pos || r < pos) return;
    if (l == r)
    {
        mn[id] = val;
        return;
    }
    int mid = (l+r)>>1;
    update_mn(id<<1,l,mid,pos,val);
    update_mn(id<<1|1,mid+1,r,pos,val);
    mn[id] = min(mn[id<<1],mn[id<<1|1]);
}

void update_sum(int id, int l, int r, int pos)
{
    if (l > pos || r < pos) return;
    if (l == r)
    {
        sum[id] = 1;
        return;
    }
    int mid = (l+r)>>1;
    update_sum(id<<1,l,mid,pos);
    update_sum(id<<1|1,mid+1,r,pos);
    sum[id] = sum[id<<1]+sum[id<<1|1];
}

int get(int id, int l, int r, int L, int R, int val)
{
    if (l > R || L > r || (l==r && mn[id]<val)) return 0;
    if (L <= l && r <= R && mn[id] >= val && mn[id] != INF)
        return sum[id];
    int mid = (l+r)>>1;
    return get(id<<1,l,mid,L,R,val) + get(id<<1|1,mid+1,r,L,R,val);
}

int main()
{
    scanf("%d %d",&n,&qu);
    for (int i = 0; i < 8*N; i++)
        mn[i] = INF;
    for (int i = 0; i < n; i++)
    {
        scanf("%d %d",&q[i].x,&q[i].y);
        q[i].x++;
        q[i].y++;
        q[i].s = q[i].x + q[i].y;
    }
    for (int i = 0; i < qu; i++)
    {
        scanf("%d %d %d",&q[i+n].x,&q[i+n].y,&q[i+n].s);
        q[i+n].x++, q[i+n].y++, q[i+n].s += 2;
        q[i+n].id = i;
        q[i+n].type = 1;
    }
    sort(q,q+n+qu);
    //for (int i = 0; i < n+qu; i++)
    //{
    //    cout << q[i].x << ' ' << q[i].y << ' ' << q[i].s << ' ' << q[i].id << ' ' << q[i].type << endl;
    //}
    for (int i = 0; i < n+qu; i++)
    {
        if (!q[i].type)
        {
            update_mn(1,1,2*N,q[i].s,q[i].y);
            update_sum(1,1,2*N,q[i].s);
        }
        else
        {
            ans[q[i].id] = get(1,1,2*N,q[i].s,2*N,q[i].y);
        }
    }
    for (int i = 0; i < qu; i++)
    {
        printf("%d\n",ans[i]);
    }
}

Compilation message

examination.cpp: In function 'int main()':
examination.cpp:58:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d",&n,&qu);
     ~~~~~^~~~~~~~~~~~~~~~
examination.cpp:63:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d",&q[i].x,&q[i].y);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
examination.cpp:70:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d %d",&q[i+n].x,&q[i+n].y,&q[i+n].s);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 10 ms 6836 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 94 ms 17232 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 94 ms 17232 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 10 ms 6836 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -