이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//#pragma GCC optimize "-O3"
#include <bits/stdc++.h>
using namespace std;
int a[505],b[505];
const int MOD = 1000*1000*1000+7;
struct node{
node *l;
node *r;
int val;
node():l(NULL),r(NULL),val(0){}
};
void update(node *v, int s,int e,int l,int r,int val){
if(l>r) return;
if(s == l && e == r){
v->val += val;
return;
}
int m = (s+e)/2;
if(v->l == NULL){
v->l = new node();
v->r = new node();
}
update(v->l,s,m,l,min(m,r),val);
update(v->r,m+1,e,max(l,m+1),r,val);
v->val = (v->l->val+v->r->val)%MOD;
}
int query(node *v, int s,int e,int l,int r){
if(v == NULL) return 0;
if(l>r) return 0;
if(s == l && e == r) return v->val;
int m = (s+e)/2;
return (query(v->l,s,m,l,min(m,r))+query(v->r,m+1,e,max(l,m+1),r))%MOD;
}
int main(){
int n;
scanf("%d",&n);
for(int i = 1;i<=n;i++){
scanf("%d%d",&a[i],&b[i]);
}
node* root = new node();;
for(int i = 1;i<=n;i++){
vector<int> v;
int p = 0;
for(int j = a[i];j<=b[i];j++){
int x = query(root,1,1000*1000*1000,1,j-1);
v.push_back(x);
}
for(int j = a[i];j<=b[i];j++){
update(root,1,1000*1000*1000,j,j,v[p]+1);
p++;
}
}
cout<<query(root,1,1000*1000*1000,1,1000*1000*1000)<<endl;
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
boat.cpp: In function 'int main()':
boat.cpp:36:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&n);
~~~~~^~~~~~~~~
boat.cpp:38:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&a[i],&b[i]);
~~~~~^~~~~~~~~~~~~~~~~~~~
# | 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... |