Submission #805965

# Submission time Handle Problem Language Result Execution time Memory
805965 2023-08-04T03:48:54 Z mrwang None (JOI16_matryoshka) C++14
100 / 100
287 ms 24140 KB
#include<bits/stdc++.h>
#define TASKNAME "codeforce"
#define pb push_back
#define pli pair<int,int>
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
using ll=long long;
const ll maxN=3e5+10;
const ll inf=1e18;
const ll mod=1e9+7;
ll st[4*maxN];
ll n;

void upd(ll p,ll v,ll id=1,ll l=1,ll r=n)
{
    if(l==r)
    {
        st[id]=v;
        return;
    }
    ll mid=l+r>>1;
    if(p<=mid) upd(p,v,id*2,l,mid);
    else upd(p,v,id*2+1,mid+1,r);
    st[id]=max(st[id*2],st[id*2+1]);
}
ll get(ll i,ll j,ll id=1,ll l=1,ll r=n)
{
    if(j<l||r<i) return 0;
    if(i<=l&&r<=j) return st[id];
    ll mid=l+r>>1;
    return max(get(i,j,id*2,l,mid),get(i,j,id*2+1,mid+1,r));
}
ll q;
struct qq
{
    ll h,r;
    bool operator<(const qq&o)
    {
        if(h==o.h) return r>o.r;
        return h<o.h;
    }
}a[maxN];
bool cmp(pli x,pli y)
{
    if(x.fi==y.fi) return x.se>y.se;
    return x.fi<y.fi;
}
struct qq2
{
    ll fi,se,id;
    bool operator<(const qq2&o)
    {
        return fi<o.fi;
    }
}t[maxN];
ll ans[maxN];
void solve()
{
    cin >> n >> q;
    for(int i=1;i<=n;i++)
    {
        cin >> a[i].h >> a[i].r;
    }
    sort(a+1,a+n+1);
    // tim day con ko giam dai nhat ? ....
    vector<pli> vec;
    for(int i=1;i<=n;i++)
    {
        vec.pb({a[i].r,i});
    }
    sort(vec.begin(),vec.end(),cmp);
    for(int i=1;i<=q;i++)
    {
        cin >> t[i].se >> t[i].fi;
        t[i].id=i;
    }
    sort(t+1,t+q+1);
    ll j=0;
    for(int i=1;i<=q;i++)
    {
        while(j<n&&vec[j].fi<=t[i].fi)
        {
            ll p=vec[j].se;
            ll x=get(p+1,n)+1;
            upd(p,x);
            j++;
        }
        ll low=1,high=n;
        while(low<=high)
        {
            ll mid=low+high>>1;
            if(a[mid].h>=t[i].se) high=mid-1;
            else low=mid+1;
        }
        ans[t[i].id]=get(low,n);
    }
    for(int i=1;i<=q;i++) cout << ans[i]<<'\n';
}
int main()
{
    fastio
    //freopen(TASKNAME".INP","r",stdin);
    //freopen(TASKNAME".OUT","w",stdout);
    solve();
}

Compilation message

matryoshka.cpp: In function 'void upd(ll, ll, ll, ll, ll)':
matryoshka.cpp:23:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   23 |     ll mid=l+r>>1;
      |            ~^~
matryoshka.cpp: In function 'll get(ll, ll, ll, ll, ll)':
matryoshka.cpp:32:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   32 |     ll mid=l+r>>1;
      |            ~^~
matryoshka.cpp: In function 'void solve()':
matryoshka.cpp:93:23: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   93 |             ll mid=low+high>>1;
      |                    ~~~^~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 2 ms 596 KB Output is correct
24 Correct 2 ms 560 KB Output is correct
25 Correct 2 ms 600 KB Output is correct
26 Correct 2 ms 468 KB Output is correct
27 Correct 2 ms 472 KB Output is correct
28 Correct 2 ms 468 KB Output is correct
29 Correct 2 ms 536 KB Output is correct
30 Correct 2 ms 468 KB Output is correct
31 Correct 3 ms 596 KB Output is correct
32 Correct 2 ms 604 KB Output is correct
33 Correct 2 ms 596 KB Output is correct
34 Correct 2 ms 600 KB Output is correct
35 Correct 2 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 2 ms 596 KB Output is correct
24 Correct 2 ms 560 KB Output is correct
25 Correct 2 ms 600 KB Output is correct
26 Correct 2 ms 468 KB Output is correct
27 Correct 2 ms 472 KB Output is correct
28 Correct 2 ms 468 KB Output is correct
29 Correct 2 ms 536 KB Output is correct
30 Correct 2 ms 468 KB Output is correct
31 Correct 3 ms 596 KB Output is correct
32 Correct 2 ms 604 KB Output is correct
33 Correct 2 ms 596 KB Output is correct
34 Correct 2 ms 600 KB Output is correct
35 Correct 2 ms 600 KB Output is correct
36 Correct 287 ms 21408 KB Output is correct
37 Correct 235 ms 20668 KB Output is correct
38 Correct 77 ms 8708 KB Output is correct
39 Correct 230 ms 19168 KB Output is correct
40 Correct 209 ms 19656 KB Output is correct
41 Correct 226 ms 20684 KB Output is correct
42 Correct 142 ms 18316 KB Output is correct
43 Correct 110 ms 18484 KB Output is correct
44 Correct 286 ms 23968 KB Output is correct
45 Correct 246 ms 23992 KB Output is correct
46 Correct 281 ms 24012 KB Output is correct
47 Correct 232 ms 23652 KB Output is correct
48 Correct 237 ms 24132 KB Output is correct
49 Correct 227 ms 23752 KB Output is correct
50 Correct 230 ms 24140 KB Output is correct