이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2")
#include<bits/stdc++.h>
#define int long long
//#define ll long long
#define down cout<<'\n';
#define NHP ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);
#define modwwe int t;cin>>t; while(t--)
#define bit(i,j) (i>>j&1)
#define sobit(a) __builtin_popcountll(a)
#define task "test"
#define fin(x) freopen(x".inp","r",stdin)
#define fou(x) freopen(x".out","w",stdout)
#define pb push_back
#define checktime cerr << (double)clock() / CLOCKS_PER_SEC * 1000 << " ms";
using namespace std;
void ngha();
const int mod2=1e9+7;
const int mod1=998244353;
struct ib
{
int a;
int b;
};
struct icd
{
int a,b;
};
struct ic
{
int a,b,c;
};
struct id
{
int a,b,c,d;
};
struct ie
{
int a,b,c, d,e;
};
int n,m,s2,s4,s3,sf,k,r,mid,s5,s6,mx,s7,s8,s9,mx2,res,dem2=0,dem=0,l;
int i,s10,s12;
int el=29;
main()
{
//#ifndef ONLINE_JUDGE
// fin(task),fou(task);
//#endif
NHP
//modwwe
// cin>>res;
ngha(),down
checktime
}
/// chi can quan tam den so be nhat(voi khuc dau)
/// chi can quan tam den so lon nhat( voi khuc cuoi)
int t[1200001];
id a[100001];
int dp2[100001];
void build(int node,int l,int r)
{ t[node]=1e18;
if(l==r) return;
int mid=l+r>>1;
build(node<<1,l,mid);
build(node<<1|1,mid+1,r);
}
void upd(int node,int l,int r,int l1,int r1,int k)
{
if(l>r1||r<l1) {
// if(l1==9&&r1==9&&k==7) cout<<l<<" "<<r<<" "<<node,down
return;}
if(l>=l1&&r<=r1)
{
t[node]=min(t[node],k);
return;
}
int mid=l+r>>1;
upd(node<<1,l,mid,l1,r1,k);
upd(node<<1|1,mid+1,r,l1,r1,k);
t[node]=min(t[node<<1],t[node<<1|1]);
}
int get(int node,int l,int r,int l1,int r1)
{
if(l>r1||r<l1) return 1e18;
if(l>=l1&&r<=r1)
{
return t[node];
}
int mid=l+r>>1;
return min(get(node<<1,l,mid,l1,r1),get(node<<1|1,mid+1,r,l1,r1));
}
int dp1[100001];
vector<int> v;
void ngha()
{
cin>>n>>m;
for(int i=1;i<=n;i++)
{
cin>>a[i].a>>a[i].b>>a[i].c>>a[i].d;
v.pb(a[i].a);
v.pb(a[i].b);
v.pb(a[i].c);
}
sort(v.begin(),v.end());
for(int i=1;i<=n;i++)
{
a[i].a=lower_bound(v.begin(),v.end(),a[i].a)-v.begin()+1;
a[i].b=lower_bound(v.begin(),v.end(),a[i].b)-v.begin()+1;
a[i].c=lower_bound(v.begin(),v.end(),a[i].c)-v.begin()+1;
}
/// xet doan 1 (doan tien to)
build(1,1,n*3);
for(int i=1;i<=n;i++)
{ dp1[i]=get(1,1,n*3,a[i].a,a[i].b)+a[i].d;
if(v[a[i].a-1]==1) dp1[i]=a[i].d;
upd(1,1,n*3,a[i].c,a[i].c,dp1[i]);
}
build(1,1,n*3);
/// xet doan 2(doan hau to)
/// khong so dung chung do chi xet cac khuc tinh tien cai nho nhat
/// neu chung nhau khi doan nho nhat phai bang nhau
for(int i=1;i<=n;i++)
{
dp2[i]=get(1,1,n*3,a[i].a,a[i].b)+a[i].d;
if(v[a[i].b-1]==m) dp2[i]=a[i].d;
upd(1,1,n*3,a[i].c,a[i].c,dp2[i]);
}
s2=1e18;
for(int i=1;i<=n;i++)
{
s2=min(s2,dp1[i]+dp2[i]-a[i].d);
}
if(s2==1e18) cout<<-1;
else cout<<s2;
}
컴파일 시 표준 에러 (stderr) 메시지
pinball.cpp:45:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
45 | main()
| ^~~~
pinball.cpp: In function 'void build(long long int, long long int, long long int)':
pinball.cpp:64:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
64 | int mid=l+r>>1;
| ~^~
pinball.cpp: In function 'void upd(long long int, long long int, long long int, long long int, long long int, long long int)':
pinball.cpp:78:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
78 | int mid=l+r>>1;
| ~^~
pinball.cpp: In function 'long long int get(long long int, long long int, long long int, long long int, long long int)':
pinball.cpp:90:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
90 | int mid=l+r>>1;
| ~^~
# | 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... |