Submission #959475

# Submission time Handle Problem Language Result Execution time Memory
959475 2024-04-08T09:35:00 Z modwwe Pinball (JOI14_pinball) C++17
100 / 100
193 ms 21200 KB
#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;
}

Compilation message

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
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4560 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 2 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4560 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 2 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 2 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4560 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 2 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 2 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4552 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 2 ms 4444 KB Output is correct
18 Correct 2 ms 4444 KB Output is correct
19 Correct 2 ms 4444 KB Output is correct
20 Correct 2 ms 4440 KB Output is correct
21 Correct 2 ms 4576 KB Output is correct
22 Correct 3 ms 4440 KB Output is correct
23 Correct 2 ms 4444 KB Output is correct
24 Correct 2 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4560 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 2 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 2 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4552 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 2 ms 4444 KB Output is correct
18 Correct 2 ms 4444 KB Output is correct
19 Correct 2 ms 4444 KB Output is correct
20 Correct 2 ms 4440 KB Output is correct
21 Correct 2 ms 4576 KB Output is correct
22 Correct 3 ms 4440 KB Output is correct
23 Correct 2 ms 4444 KB Output is correct
24 Correct 2 ms 4444 KB Output is correct
25 Correct 15 ms 5340 KB Output is correct
26 Correct 41 ms 10276 KB Output is correct
27 Correct 137 ms 15148 KB Output is correct
28 Correct 176 ms 21200 KB Output is correct
29 Correct 85 ms 13952 KB Output is correct
30 Correct 181 ms 20416 KB Output is correct
31 Correct 183 ms 20164 KB Output is correct
32 Correct 193 ms 20928 KB Output is correct
33 Correct 23 ms 5880 KB Output is correct
34 Correct 80 ms 13944 KB Output is correct
35 Correct 117 ms 19880 KB Output is correct
36 Correct 185 ms 21060 KB Output is correct
37 Correct 157 ms 19552 KB Output is correct
38 Correct 186 ms 20148 KB Output is correct