제출 #530674

#제출 시각아이디문제언어결과실행 시간메모리
530674A_DBridges (APIO19_bridges)C++14
0 / 100
401 ms4000 KiB
#include <bits/stdc++.h>

#define int long long
#define ii pair<int,int>
#define F first
#define S second

using namespace std;
const int N=1e5+100;
vector<int> g[N];
int seg[4*N];
void update(int p,int s,int e,int i,int v)
{
    if(s==e){
        seg[p]=v;
        return;
    }
    int mid=(s+e)/2;
    if(i<=mid){
        update(p*2,s,mid,i,v);
    }
    else{
        update(p*2+1,mid+1,e,i,v);
    }
    seg[p]=max(seg[p*2],seg[p*2+1]);
}
int get(int p,int s,int e,int a,int b)
{
    if(a<=s&&e<=b){
        return seg[p];
    }
    if(s>b||e<a)return 0;
    int mid=(s+e)/2;
    return max(get(p*2,s,mid,a,b),get(p*2+1,mid+1,e,a,b));
}
void solve()
{
    int n,m;
    cin>>n>>m;
    for(int i=1;i<n;i++){
        int b;
        scanf("%lld",&b);
        scanf("%lld",&b);
        scanf("%lld",&b);
        update(1,1,n,i,b);
    }
 //   for(int i=1;i<n;i++)cout<<get(1,1,n,i,i)<<" ";cout<<endl;
    int q;
    cin>>q;
    while(q--){
        int t;
        scanf("%lld",&t);
        if(t==1){
            int b,w;
            scanf("%lld",&b);
            scanf("%lld",&w);
            update(1,1,n,b,w);
        }
        else{
            int b,w;
            scanf("%lld",&b);
            scanf("%lld",&w);
            int ans=0;
            if(b!=1){
                int l=1,r=b-1,ann=b;
                while(l<=r){
                    int mid=(l+r)/2;
          //          cout<<mid<<" "<<get(1,1,n,mid,b-1)<<endl;
                    if(get(1,1,n,mid,b-1)<=w){
                        ann=mid;
                        r=mid-1;
                    }
                    else{
                        l=mid+1;
                    }
                }
                ans+=b-ann;
            }
        //    cout<<endl;
            if(b!=n){
                int l=b,r=n,ann=b-1;
                while(l<=r){
                    int mid=(l+r)/2;
           //         cout<<mid<<" "<<get(1,1,n,b,mid)<<endl;
                    if(get(1,1,n,b,mid)<=w){
                        ann=mid;
                        l=mid+1;
                    }
                    else{
                        r=mid-1;
                    }
                }
                ans+=ann-b+1;
            }
            printf("%lld\n",ans);
        }
    }
}
main()
{
    int t=1;
//    cin>>t;
    while(t--){
        solve();
    }
}

컴파일 시 표준 에러 (stderr) 메시지

bridges.cpp:99:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   99 | main()
      | ^~~~
bridges.cpp: In function 'void solve()':
bridges.cpp:42:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 |         scanf("%lld",&b);
      |         ~~~~~^~~~~~~~~~~
bridges.cpp:43:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   43 |         scanf("%lld",&b);
      |         ~~~~~^~~~~~~~~~~
bridges.cpp:44:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   44 |         scanf("%lld",&b);
      |         ~~~~~^~~~~~~~~~~
bridges.cpp:52:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   52 |         scanf("%lld",&t);
      |         ~~~~~^~~~~~~~~~~
bridges.cpp:55:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   55 |             scanf("%lld",&b);
      |             ~~~~~^~~~~~~~~~~
bridges.cpp:56:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   56 |             scanf("%lld",&w);
      |             ~~~~~^~~~~~~~~~~
bridges.cpp:61:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   61 |             scanf("%lld",&b);
      |             ~~~~~^~~~~~~~~~~
bridges.cpp:62:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   62 |             scanf("%lld",&w);
      |             ~~~~~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...