답안 #928582

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
928582 2024-02-16T17:14:54 Z haru09 Exhibition (JOI19_ho_t2) C++17
0 / 100
1 ms 2648 KB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second
#define task "code"

const int ar=1e5+5;
const ll mod=1e9+7;
int n,m;
stack<int> s;
vector<pair<int,int>> it;
int leftmin[ar];
int rightmin[ar];
pair<int,int> pic[ar];
int c[ar];
int pos(int val)
{
    return lower_bound(c+1,c+m+1,val)-c;
}
int st[(1<<18)+5];
int lz[(1<<18)+5];
void down(int id,int l,int r)
{
    if (!lz[id]) return;
    st[id]+=lz[id];
    if (l!=r)
    {
        lz[id<<1]+=lz[id];
        lz[id<<1|1]+=lz[id];
    }
    lz[id]=0;
}
void update_point(int p,int val)
{
    if (p<1 || p>n) return;
    int id=1;
    int l=1;
    int r=n;
    while(l<r)
    {
        int mid=l+r>>1;
        down(id<<1,l,mid);
        down(id<<1|1,mid+1,r);
        if (mid>=p)
        {
            id<<=1;
            r=mid;
        }
        else
        {
            id=id<<1|1;
            l=mid+1;
        }
    }
    st[id]=val;
    while(id>1)
    {
        id>>=1;
        st[id]=max(st[id<<1],st[id<<1|1]);
    }
}
void update(int id,int l,int r,int u,int v,ll val)
{
    if (u>v) return;
    down(id,l,r);
    if (l>v || r<u) return;
    if (u<=l && r<=v)
    {
        lz[id]+=val;
        down(id,l,r);
        return;
    }
    int m=l+r>>1;
    update(id<<1,l,m,u,v,val);
    update(id<<1|1,m+1,r,u,v,val);
    st[id]=max(st[id<<1],st[id<<1|1]);
}
int get(int id, int l, int r, int u, int v) {
    if (u==0) return 0;
    down(id,l,r);
    if(l >= u && r <= v)
    {
        return st[id];
    }
    int mid = l + r >> 1;
    if(mid >= u) {
        if(mid + 1 <= v)
            return max(get(id << 1, l, mid, u, v) , get(id << 1 | 1, mid + 1, r, u, v));
        return get(id << 1, l, mid, u, v);
    }
    return get(id << 1 | 1, mid + 1, r, u, v);
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    if (fopen(task".inp","r"))
    {
        freopen(task".inp","r",stdin);
        freopen(task".out","w",stdout);
    }
    cin>>n>>m;
    for (int i=1;i<=n;i++)
    {
        cin>>pic[i].se>>pic[i].fi;
    }
    for (int i=1;i<=m;i++)
    {
        cin>>c[i];
    }
    sort(c+1,c+m+1);
    sort(pic+1,pic+n+1);
    pic[0].se=0;
    s.push(0);
    for (int i=1;i<=n;i++)
    {
        while(pic[i].se<pic[s.top()].se)
        {
            s.pop();
        }
        leftmin[i]=s.top();
        s.push(i);
    }
    pic[n+1].se=0;
    while(s.size()) s.pop();
    s.push(n+1);
    for (int i=n;i>=1;i--)
    {
        while(pic[i].se<pic[s.top()].se)
        {
            s.pop();
        }
        rightmin[i]=s.top();
        s.push(i);
    }
    for (int i=1;i<=n;i++)
    {
        it.push_back({pic[i].se,i});
    }
    sort(it.begin(),it.end());
    int ans=0;
    for (auto [w,i]:it)
    {
        int prepos=get(1,1,n,leftmin[i],leftmin[i]);
        int canbepos=pos(w);
        int realpos=max(canbepos,prepos+1);
        update_point(i,realpos);
        int nextpos=get(1,1,n,rightmin[i],rightmin[i]);
        if (nextpos)
        {
            update(1,1,n,i+1,n,realpos-nextpos+1);
        }
        int ma=get(1,1,n,1,n);
        if (ma>m) return cout<<ans,0;
        ans++;
    }
    cout<<ans;
}

Compilation message

joi2019_ho_t2.cpp: In function 'void update_point(int, int)':
joi2019_ho_t2.cpp:42:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   42 |         int mid=l+r>>1;
      |                 ~^~
joi2019_ho_t2.cpp: In function 'void update(int, int, int, int, int, long long int)':
joi2019_ho_t2.cpp:74:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   74 |     int m=l+r>>1;
      |           ~^~
joi2019_ho_t2.cpp: In function 'int get(int, int, int, int, int)':
joi2019_ho_t2.cpp:86:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   86 |     int mid = l + r >> 1;
      |               ~~^~~
joi2019_ho_t2.cpp: In function 'int main()':
joi2019_ho_t2.cpp:100:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  100 |         freopen(task".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
joi2019_ho_t2.cpp:101:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  101 |         freopen(task".out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2524 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2512 KB Output is correct
7 Correct 1 ms 2648 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2520 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Incorrect 1 ms 2396 KB Output isn't correct
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2524 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2512 KB Output is correct
7 Correct 1 ms 2648 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2520 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Incorrect 1 ms 2396 KB Output isn't correct
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2524 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2512 KB Output is correct
7 Correct 1 ms 2648 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2520 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Incorrect 1 ms 2396 KB Output isn't correct
14 Halted 0 ms 0 KB -