답안 #690501

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
690501 2023-01-30T08:48:12 Z White Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
0 / 100
182 ms 262144 KB
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;

vector<pair<long long,long long>>ans[1000005];
long long red[1000005];
stack<pair<long long,long long>>s;

long long binary(long long v,long long num){

    long long l=0,r=ans[v].size()-1;
    while(l<r){
        long long mid=(r+l)/2;
        if(ans[v][mid].second<num)l=mid+1;
        else r=mid;
    }

    return l;
}

int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    long long n,m;
    cin>>n>>m;
    for(long long i=0;i<n;i++)cin>>red[i];
    s.push({red[0],0});
    for(long long i=1;i<n;i++){
            ans[i]=ans[i-1];
            while(s.empty()!=true && red[i]>=s.top().first)s.pop();
            if(s.empty()!=true){
                ans[i].push_back({s.top().first+red[i],s.top().second});
                for(long long j=0;j<ans[i].size()-1;j++){
                    if(ans[i][j].first<red[ans[i][j].second]+red[i]){
                        ans[i][j].first=red[ans[i][j].second]+red[i];
                    }
                }

            }
            s.push({red[i],i});
    }

    /**
    for(long long i=0;i<n;i++){
            cout<<i<<": ";
        for(long long j=0;j<ans[i].size();j++){
            cout<<ans[i][j].first<<";"<<ans[i][j].second<<" ";
        }
        cout<<endl;
    }
    **/

    for(long long i=0;i<m;i++){
        long long a,b,c,now;
        cin>>a>>b>>c;
        a--;b--;
        now=binary(b,a);
        if(now>=ans[b].size())now--;
        if(ans[b].empty() || ans[b][now].second<a)cout<<1<<endl;
        else {
            while(now<ans[a].size() && ans[a][now].first==ans[b][now].first)now++;
            if(now>=ans[b].size())cout<<1<<endl;
            else{
            if(ans[b].size()==0 || c>=ans[b][now].first)cout<<1<<endl;
            else cout<<0<<endl;
            }
        }
    }

    return 0;
}

Compilation message

sortbooks.cpp: In function 'int main()':
sortbooks.cpp:35:36: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |                 for(long long j=0;j<ans[i].size()-1;j++){
      |                                   ~^~~~~~~~~~~~~~~~
sortbooks.cpp:60:15: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |         if(now>=ans[b].size())now--;
      |            ~~~^~~~~~~~~~~~~~~
sortbooks.cpp:63:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |             while(now<ans[a].size() && ans[a][now].first==ans[b][now].first)now++;
      |                   ~~~^~~~~~~~~~~~~~
sortbooks.cpp:64:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   64 |             if(now>=ans[b].size())cout<<1<<endl;
      |                ~~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23764 KB Output is correct
2 Correct 12 ms 23812 KB Output is correct
3 Incorrect 16 ms 24148 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23764 KB Output is correct
2 Correct 12 ms 23812 KB Output is correct
3 Incorrect 16 ms 24148 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 182 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 107 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23764 KB Output is correct
2 Correct 12 ms 23812 KB Output is correct
3 Incorrect 16 ms 24148 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23764 KB Output is correct
2 Correct 12 ms 23812 KB Output is correct
3 Incorrect 16 ms 24148 KB Output isn't correct
4 Halted 0 ms 0 KB -