이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 < 4*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]);
}
}
컴파일 시 표준 에러 (stderr) 메시지
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);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |