답안 #1093239

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1093239 2024-09-26T10:36:29 Z ivaziva Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
0 / 100
2773 ms 140040 KB
#include <bits/stdc++.h>

using namespace std;

#define MAXN 1000001

int n,m;
int w[MAXN];
int last[MAXN];
stack<pair<int,int>> st;
vector<pair<int,pair<int,int>>> queries[MAXN];
vector<int> lasts[MAXN];
int seg[MAXN*4];
int ans[MAXN];

void build(int node,int l,int r)
{
    if (l==r)
    {
        if (last[l]==-1) seg[node]=w[l];
        else seg[node]=w[l]+w[last[l]];
    }
    else
    {
        int mid=(l+r)/2;
        build(2*node,l,mid);build(2*node+1,mid+1,r);
        seg[node]=max(seg[2*node],seg[2*node+1]);
    }
}

void update(int node,int l,int r,int pos,int val)
{
    if (l==r) seg[node]=val;
    else
    {
        int mid=(l+r)/2;
        if (pos<=mid) update(2*node,l,mid,pos,val);
        else update(2*node+1,mid+1,r,pos,val);
        seg[node]=max(seg[2*node],seg[2*node+1]);
    }
}

int query(int node,int l,int r,int a,int b)
{
    if (a>b) return -INT_MAX;
    if (l==a and r==b) return seg[node];
    int mid=(l+r)/2;
    return max(query(2*node,l,mid,a,min(b,mid)),query(2*node+1,mid+1,r,max(a,mid+1),b));
}

int main()
{
    cin>>n>>m;
    for (int i=1;i<=n;i++) cin>>w[i];
    for (int i=1;i<=n;i++)
    {
        while (st.size()!=0 and st.top().first<=w[i]) st.pop();
        if (st.size()==0) last[i]=-1;
        else last[i]=st.top().second;
        st.push({w[i],i});
        if (last[i]!=-1) lasts[last[i]].push_back(i);
    }
    for (int i=0;i<m;i++)
    {
        int l,r,k;cin>>l>>r>>k;
        queries[l].push_back({r,{k,i}});
    }
    for (int i=1;i<=n;i++) sort(queries[i].begin(),queries[i].end());
    build(1,1,n);
    for (int levo=1;levo<=n;levo++)
    {
        for (int p:lasts[levo-1]) update(1,1,n,p,0);
        for (int siz=0;siz<queries[levo].size();siz++)
        {
            int desno=queries[levo][siz].first;
            int val=queries[levo][siz].second.first;
            int poz=queries[levo][siz].second.second;
            if (query(1,1,n,levo,desno)<=val) ans[poz]=1;
            else ans[poz]=0;
        }
    }
    for (int i=0;i<m;i++) cout<<ans[i]<<endl;
}

Compilation message

sortbooks.cpp: In function 'int main()':
sortbooks.cpp:73:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   73 |         for (int siz=0;siz<queries[levo].size();siz++)
      |                        ~~~^~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 47196 KB Output is correct
2 Correct 21 ms 47192 KB Output is correct
3 Incorrect 24 ms 47448 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 47196 KB Output is correct
2 Correct 21 ms 47192 KB Output is correct
3 Incorrect 24 ms 47448 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2581 ms 138916 KB Output is correct
2 Correct 2589 ms 140040 KB Output is correct
3 Correct 2619 ms 139856 KB Output is correct
4 Correct 2773 ms 139944 KB Output is correct
5 Incorrect 2616 ms 123812 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 226 ms 55604 KB Output is correct
2 Correct 221 ms 55380 KB Output is correct
3 Incorrect 210 ms 53828 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 47196 KB Output is correct
2 Correct 21 ms 47192 KB Output is correct
3 Incorrect 24 ms 47448 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 47196 KB Output is correct
2 Correct 21 ms 47192 KB Output is correct
3 Incorrect 24 ms 47448 KB Output isn't correct
4 Halted 0 ms 0 KB -