Submission #439458

# Submission time Handle Problem Language Result Execution time Memory
439458 2021-06-30T04:09:03 Z fcmalkcin Food Court (JOI21_foodcourt) C++17
68 / 100
1000 ms 58692 KB
#include <bits/stdc++.h>
using namespace std;
#define ll  long long
#define pll pair<ll,ll>
#define ff first
#define ss second
#define pb push_back
#define endl "\n"
const ll maxn=3e5+10;
const ll mod =998244353 ;
const ll base=3e18;
vector<pair<pll,ll>> adj[maxn];
vector<pll> p[maxn];

struct tk
{
    ll val,c;
    ll mn,mx;
    ll ps;
    ll chk;
};
tk st[4*maxn];
tk mer(tk a,tk b)
{
    if (a.chk==-1) return b;
    if (b.chk==-1) return a;
    tk c;
    c.val=a.val+b.val;
    c.chk=a.chk;
    c.mn=min(a.mn,a.val+b.mn);
    c.mx=max(a.mx,a.val+b.mx);
    c.ps=a.ps+b.ps;
    c.c=-1;
    return c;
}
void build(ll id,ll left,ll right)
{
    st[id].val=0;
    st[id].chk=-1;
    st[id].c=-1;
    st[id].mn=0;
    st[id].mx=0;
    st[id].ps=0;
    if (left==right) return ;
    ll mid=(left+right)/2;
    build(id*2,left,mid);
    build(id*2+1,mid+1,right);
    st[id]=mer(st[id*2],st[id*2+1]);
}
void update(ll id,ll left,ll right,ll x,ll val,ll c)
{
    if (x>right||x<left) return ;
    if (left==right)
    {
        st[id].val=val;
        st[id].mx=max(0ll,st[id].val);
        st[id].mn=min(0ll,st[id].val);
        st[id].chk=(val>=0);
        st[id].ps=max(0ll,st[id].val);
        st[id].c=c;
        return ;
    }
    ll mid=(left+right)/2;
    update(id*2,left,mid,x,val,c);
    update(id*2+1,mid+1,right,x,val,c);
    st[id]=mer(st[id*2],st[id*2+1]);
}
tk get(ll id,ll left,ll right,ll x,ll y)
{
    tk p;
    p.chk=-1;
    if (x>right||y<left) return p;
    if (x<=left&&y>=right)
    {
        return st[id];
    }
    ll mid=(left+right)/2;
    return mer(get(id*2,left,mid,x,y),get(id*2+1,mid+1,right,x,y));
}
ll ans[maxn];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    if (fopen("t.inp", "r"))
    {
        freopen("test.inp", "r", stdin);
        freopen("test.out", "w", stdout);
    }
    memset(ans,-1,sizeof(ans));
    ll n, m, q;
    cin>> n>> m>> q;
    for (int i=1; i<=q; i++)
    {
        ll t;
        cin>> t;
        if (t==1)
        {
            ll l, r, c, k;
            cin>> l>> r>> c>> k;
            adj[l].pb(make_pair(make_pair(i,c),k));
            adj[r+1].pb(make_pair(make_pair(i,c),0));
        }
        else if (t==2)
        {
             ll l, r, c, k;
            cin>> l>> r>> k;
            c=-1;
            adj[l].pb(make_pair(make_pair(i,c),-k));
            adj[r+1].pb(make_pair(make_pair(i,c),0));
        }
        else
        {
            ll a, b;
             cin>> a>> b;
             p[a].pb(make_pair(i,b));
        }
    }
    build(1,1,q+1);
    update(1,1,q+1,1,-base,-1);
    for (int i=1;i<=n;i++)
    {
           for (auto p:adj[i])
           {
               update(1,1,q+1,p.ff.ff+1,p.ss,p.ff.ss);
           }
           for (auto to:p[i])
           {
               ll val=to.ss;
               ll pos=to.ff+1;
               tk h=get(1,1,q+1,1,pos);
               ll nw=h.val-h.mn;
               ans[pos-1]=0;
           // if (i==3)   cout <<nw<<" "<<val<<" "<<i<<endl;
               if (nw>=val)
               {
                   ll sl=nw-val+1;
             //    if (i==3) cout <<sl<<" "<<pos<<endl;
                   ll l=1, h=pos;
                   while (l<=h)
                   {
                       ll mid=(l+h)/2;
                       tk g=get(1,1,q+1,mid,pos);
                       if (g.ps>=sl) l=mid+1;
                       else h=mid-1;
                   }
                   tk g=get(1,1,q+1,h,h);
                  /* if (i==3)
                   {
                   cout <<h<<" wtf"<<endl;
                   cout <<g.c<<" "<<g.mn<<" "<<g.mx<<" "<<g.ps<<" "<<g.val<<endl;
                   }*/
                   ans[pos-1]=g.c;
               }
           }
    }
    for (int i=1;i<=q;i++)
    {
        if (ans[i]==-1) continue;
        cout <<ans[i]<<endl;
    }
    /*3 5 5
1 2 3 5 2
1 1 2 2 4
2 1 3 3
1 2 3 4 2
3 3 2*/

}

Compilation message

foodcourt.cpp: In function 'int main()':
foodcourt.cpp:89:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   89 |         freopen("test.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
foodcourt.cpp:90:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   90 |         freopen("test.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 15 ms 16972 KB Output is correct
2 Correct 18 ms 16972 KB Output is correct
3 Correct 14 ms 16972 KB Output is correct
4 Correct 17 ms 16972 KB Output is correct
5 Correct 16 ms 17100 KB Output is correct
6 Correct 15 ms 16972 KB Output is correct
7 Correct 16 ms 17028 KB Output is correct
8 Correct 16 ms 16972 KB Output is correct
9 Correct 16 ms 16972 KB Output is correct
10 Correct 16 ms 17028 KB Output is correct
11 Correct 17 ms 17068 KB Output is correct
12 Correct 16 ms 17072 KB Output is correct
13 Correct 17 ms 17068 KB Output is correct
14 Correct 15 ms 17112 KB Output is correct
15 Correct 14 ms 16972 KB Output is correct
16 Correct 16 ms 17100 KB Output is correct
17 Correct 14 ms 16948 KB Output is correct
18 Correct 16 ms 16972 KB Output is correct
19 Correct 16 ms 17012 KB Output is correct
20 Correct 16 ms 16980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 16972 KB Output is correct
2 Correct 18 ms 16972 KB Output is correct
3 Correct 14 ms 16972 KB Output is correct
4 Correct 17 ms 16972 KB Output is correct
5 Correct 16 ms 17100 KB Output is correct
6 Correct 15 ms 16972 KB Output is correct
7 Correct 16 ms 17028 KB Output is correct
8 Correct 16 ms 16972 KB Output is correct
9 Correct 16 ms 16972 KB Output is correct
10 Correct 16 ms 17028 KB Output is correct
11 Correct 17 ms 17068 KB Output is correct
12 Correct 16 ms 17072 KB Output is correct
13 Correct 17 ms 17068 KB Output is correct
14 Correct 15 ms 17112 KB Output is correct
15 Correct 14 ms 16972 KB Output is correct
16 Correct 16 ms 17100 KB Output is correct
17 Correct 14 ms 16948 KB Output is correct
18 Correct 16 ms 16972 KB Output is correct
19 Correct 16 ms 17012 KB Output is correct
20 Correct 16 ms 16980 KB Output is correct
21 Correct 18 ms 17052 KB Output is correct
22 Correct 18 ms 16972 KB Output is correct
23 Correct 18 ms 17100 KB Output is correct
24 Correct 18 ms 17072 KB Output is correct
25 Correct 15 ms 17100 KB Output is correct
26 Correct 15 ms 17108 KB Output is correct
27 Correct 17 ms 16972 KB Output is correct
28 Correct 16 ms 16972 KB Output is correct
29 Correct 18 ms 17068 KB Output is correct
30 Correct 20 ms 17060 KB Output is correct
31 Correct 15 ms 16976 KB Output is correct
32 Correct 15 ms 17028 KB Output is correct
33 Correct 14 ms 17056 KB Output is correct
34 Correct 16 ms 17036 KB Output is correct
35 Correct 16 ms 16972 KB Output is correct
36 Correct 19 ms 17100 KB Output is correct
37 Correct 15 ms 17040 KB Output is correct
38 Correct 15 ms 17072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 147 ms 26308 KB Output is correct
2 Correct 156 ms 26604 KB Output is correct
3 Correct 179 ms 26332 KB Output is correct
4 Correct 145 ms 26344 KB Output is correct
5 Correct 153 ms 26596 KB Output is correct
6 Correct 152 ms 26516 KB Output is correct
7 Correct 138 ms 25552 KB Output is correct
8 Correct 140 ms 25644 KB Output is correct
9 Correct 178 ms 26564 KB Output is correct
10 Correct 175 ms 26572 KB Output is correct
11 Correct 182 ms 26528 KB Output is correct
12 Correct 163 ms 26572 KB Output is correct
13 Correct 188 ms 26052 KB Output is correct
14 Correct 200 ms 26384 KB Output is correct
15 Correct 167 ms 26788 KB Output is correct
16 Correct 161 ms 26828 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1095 ms 58692 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 15 ms 16972 KB Output is correct
2 Correct 18 ms 16972 KB Output is correct
3 Correct 14 ms 16972 KB Output is correct
4 Correct 17 ms 16972 KB Output is correct
5 Correct 16 ms 17100 KB Output is correct
6 Correct 15 ms 16972 KB Output is correct
7 Correct 16 ms 17028 KB Output is correct
8 Correct 16 ms 16972 KB Output is correct
9 Correct 16 ms 16972 KB Output is correct
10 Correct 16 ms 17028 KB Output is correct
11 Correct 17 ms 17068 KB Output is correct
12 Correct 16 ms 17072 KB Output is correct
13 Correct 17 ms 17068 KB Output is correct
14 Correct 15 ms 17112 KB Output is correct
15 Correct 14 ms 16972 KB Output is correct
16 Correct 16 ms 17100 KB Output is correct
17 Correct 14 ms 16948 KB Output is correct
18 Correct 16 ms 16972 KB Output is correct
19 Correct 16 ms 17012 KB Output is correct
20 Correct 16 ms 16980 KB Output is correct
21 Correct 147 ms 26308 KB Output is correct
22 Correct 156 ms 26604 KB Output is correct
23 Correct 179 ms 26332 KB Output is correct
24 Correct 145 ms 26344 KB Output is correct
25 Correct 153 ms 26596 KB Output is correct
26 Correct 152 ms 26516 KB Output is correct
27 Correct 138 ms 25552 KB Output is correct
28 Correct 140 ms 25644 KB Output is correct
29 Correct 178 ms 26564 KB Output is correct
30 Correct 175 ms 26572 KB Output is correct
31 Correct 182 ms 26528 KB Output is correct
32 Correct 163 ms 26572 KB Output is correct
33 Correct 188 ms 26052 KB Output is correct
34 Correct 200 ms 26384 KB Output is correct
35 Correct 167 ms 26788 KB Output is correct
36 Correct 161 ms 26828 KB Output is correct
37 Correct 296 ms 25992 KB Output is correct
38 Correct 221 ms 25796 KB Output is correct
39 Correct 146 ms 25204 KB Output is correct
40 Correct 194 ms 25412 KB Output is correct
41 Correct 301 ms 26572 KB Output is correct
42 Correct 283 ms 26576 KB Output is correct
43 Correct 311 ms 26580 KB Output is correct
44 Correct 304 ms 26564 KB Output is correct
45 Correct 282 ms 26624 KB Output is correct
46 Correct 299 ms 26564 KB Output is correct
47 Correct 283 ms 25708 KB Output is correct
48 Correct 287 ms 27236 KB Output is correct
49 Correct 169 ms 25660 KB Output is correct
50 Correct 224 ms 26180 KB Output is correct
51 Correct 270 ms 26800 KB Output is correct
52 Correct 325 ms 26692 KB Output is correct
53 Correct 127 ms 26064 KB Output is correct
54 Correct 164 ms 26920 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 435 ms 25732 KB Output is correct
2 Correct 395 ms 25924 KB Output is correct
3 Correct 448 ms 26048 KB Output is correct
4 Correct 286 ms 25032 KB Output is correct
5 Correct 341 ms 25680 KB Output is correct
6 Correct 443 ms 26044 KB Output is correct
7 Correct 282 ms 24992 KB Output is correct
8 Correct 286 ms 24912 KB Output is correct
9 Correct 353 ms 25596 KB Output is correct
10 Correct 258 ms 25368 KB Output is correct
11 Correct 389 ms 26120 KB Output is correct
12 Correct 420 ms 26124 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 16972 KB Output is correct
2 Correct 18 ms 16972 KB Output is correct
3 Correct 14 ms 16972 KB Output is correct
4 Correct 17 ms 16972 KB Output is correct
5 Correct 16 ms 17100 KB Output is correct
6 Correct 15 ms 16972 KB Output is correct
7 Correct 16 ms 17028 KB Output is correct
8 Correct 16 ms 16972 KB Output is correct
9 Correct 16 ms 16972 KB Output is correct
10 Correct 16 ms 17028 KB Output is correct
11 Correct 17 ms 17068 KB Output is correct
12 Correct 16 ms 17072 KB Output is correct
13 Correct 17 ms 17068 KB Output is correct
14 Correct 15 ms 17112 KB Output is correct
15 Correct 14 ms 16972 KB Output is correct
16 Correct 16 ms 17100 KB Output is correct
17 Correct 14 ms 16948 KB Output is correct
18 Correct 16 ms 16972 KB Output is correct
19 Correct 16 ms 17012 KB Output is correct
20 Correct 16 ms 16980 KB Output is correct
21 Correct 18 ms 17052 KB Output is correct
22 Correct 18 ms 16972 KB Output is correct
23 Correct 18 ms 17100 KB Output is correct
24 Correct 18 ms 17072 KB Output is correct
25 Correct 15 ms 17100 KB Output is correct
26 Correct 15 ms 17108 KB Output is correct
27 Correct 17 ms 16972 KB Output is correct
28 Correct 16 ms 16972 KB Output is correct
29 Correct 18 ms 17068 KB Output is correct
30 Correct 20 ms 17060 KB Output is correct
31 Correct 15 ms 16976 KB Output is correct
32 Correct 15 ms 17028 KB Output is correct
33 Correct 14 ms 17056 KB Output is correct
34 Correct 16 ms 17036 KB Output is correct
35 Correct 16 ms 16972 KB Output is correct
36 Correct 19 ms 17100 KB Output is correct
37 Correct 15 ms 17040 KB Output is correct
38 Correct 15 ms 17072 KB Output is correct
39 Correct 147 ms 26308 KB Output is correct
40 Correct 156 ms 26604 KB Output is correct
41 Correct 179 ms 26332 KB Output is correct
42 Correct 145 ms 26344 KB Output is correct
43 Correct 153 ms 26596 KB Output is correct
44 Correct 152 ms 26516 KB Output is correct
45 Correct 138 ms 25552 KB Output is correct
46 Correct 140 ms 25644 KB Output is correct
47 Correct 178 ms 26564 KB Output is correct
48 Correct 175 ms 26572 KB Output is correct
49 Correct 182 ms 26528 KB Output is correct
50 Correct 163 ms 26572 KB Output is correct
51 Correct 188 ms 26052 KB Output is correct
52 Correct 200 ms 26384 KB Output is correct
53 Correct 167 ms 26788 KB Output is correct
54 Correct 161 ms 26828 KB Output is correct
55 Correct 296 ms 25992 KB Output is correct
56 Correct 221 ms 25796 KB Output is correct
57 Correct 146 ms 25204 KB Output is correct
58 Correct 194 ms 25412 KB Output is correct
59 Correct 301 ms 26572 KB Output is correct
60 Correct 283 ms 26576 KB Output is correct
61 Correct 311 ms 26580 KB Output is correct
62 Correct 304 ms 26564 KB Output is correct
63 Correct 282 ms 26624 KB Output is correct
64 Correct 299 ms 26564 KB Output is correct
65 Correct 283 ms 25708 KB Output is correct
66 Correct 287 ms 27236 KB Output is correct
67 Correct 169 ms 25660 KB Output is correct
68 Correct 224 ms 26180 KB Output is correct
69 Correct 270 ms 26800 KB Output is correct
70 Correct 325 ms 26692 KB Output is correct
71 Correct 127 ms 26064 KB Output is correct
72 Correct 164 ms 26920 KB Output is correct
73 Correct 435 ms 25732 KB Output is correct
74 Correct 395 ms 25924 KB Output is correct
75 Correct 448 ms 26048 KB Output is correct
76 Correct 286 ms 25032 KB Output is correct
77 Correct 341 ms 25680 KB Output is correct
78 Correct 443 ms 26044 KB Output is correct
79 Correct 282 ms 24992 KB Output is correct
80 Correct 286 ms 24912 KB Output is correct
81 Correct 353 ms 25596 KB Output is correct
82 Correct 258 ms 25368 KB Output is correct
83 Correct 389 ms 26120 KB Output is correct
84 Correct 420 ms 26124 KB Output is correct
85 Correct 319 ms 26072 KB Output is correct
86 Correct 329 ms 26440 KB Output is correct
87 Correct 289 ms 26100 KB Output is correct
88 Correct 291 ms 26612 KB Output is correct
89 Correct 227 ms 25368 KB Output is correct
90 Correct 324 ms 26620 KB Output is correct
91 Correct 222 ms 25956 KB Output is correct
92 Correct 209 ms 25724 KB Output is correct
93 Correct 274 ms 26576 KB Output is correct
94 Correct 307 ms 26668 KB Output is correct
95 Correct 296 ms 26500 KB Output is correct
96 Correct 285 ms 26636 KB Output is correct
97 Correct 297 ms 26548 KB Output is correct
98 Correct 233 ms 26104 KB Output is correct
99 Correct 278 ms 25588 KB Output is correct
100 Correct 237 ms 25984 KB Output is correct
101 Correct 286 ms 27076 KB Output is correct
102 Correct 228 ms 26804 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 16972 KB Output is correct
2 Correct 18 ms 16972 KB Output is correct
3 Correct 14 ms 16972 KB Output is correct
4 Correct 17 ms 16972 KB Output is correct
5 Correct 16 ms 17100 KB Output is correct
6 Correct 15 ms 16972 KB Output is correct
7 Correct 16 ms 17028 KB Output is correct
8 Correct 16 ms 16972 KB Output is correct
9 Correct 16 ms 16972 KB Output is correct
10 Correct 16 ms 17028 KB Output is correct
11 Correct 17 ms 17068 KB Output is correct
12 Correct 16 ms 17072 KB Output is correct
13 Correct 17 ms 17068 KB Output is correct
14 Correct 15 ms 17112 KB Output is correct
15 Correct 14 ms 16972 KB Output is correct
16 Correct 16 ms 17100 KB Output is correct
17 Correct 14 ms 16948 KB Output is correct
18 Correct 16 ms 16972 KB Output is correct
19 Correct 16 ms 17012 KB Output is correct
20 Correct 16 ms 16980 KB Output is correct
21 Correct 18 ms 17052 KB Output is correct
22 Correct 18 ms 16972 KB Output is correct
23 Correct 18 ms 17100 KB Output is correct
24 Correct 18 ms 17072 KB Output is correct
25 Correct 15 ms 17100 KB Output is correct
26 Correct 15 ms 17108 KB Output is correct
27 Correct 17 ms 16972 KB Output is correct
28 Correct 16 ms 16972 KB Output is correct
29 Correct 18 ms 17068 KB Output is correct
30 Correct 20 ms 17060 KB Output is correct
31 Correct 15 ms 16976 KB Output is correct
32 Correct 15 ms 17028 KB Output is correct
33 Correct 14 ms 17056 KB Output is correct
34 Correct 16 ms 17036 KB Output is correct
35 Correct 16 ms 16972 KB Output is correct
36 Correct 19 ms 17100 KB Output is correct
37 Correct 15 ms 17040 KB Output is correct
38 Correct 15 ms 17072 KB Output is correct
39 Correct 147 ms 26308 KB Output is correct
40 Correct 156 ms 26604 KB Output is correct
41 Correct 179 ms 26332 KB Output is correct
42 Correct 145 ms 26344 KB Output is correct
43 Correct 153 ms 26596 KB Output is correct
44 Correct 152 ms 26516 KB Output is correct
45 Correct 138 ms 25552 KB Output is correct
46 Correct 140 ms 25644 KB Output is correct
47 Correct 178 ms 26564 KB Output is correct
48 Correct 175 ms 26572 KB Output is correct
49 Correct 182 ms 26528 KB Output is correct
50 Correct 163 ms 26572 KB Output is correct
51 Correct 188 ms 26052 KB Output is correct
52 Correct 200 ms 26384 KB Output is correct
53 Correct 167 ms 26788 KB Output is correct
54 Correct 161 ms 26828 KB Output is correct
55 Execution timed out 1095 ms 58692 KB Time limit exceeded
56 Halted 0 ms 0 KB -