Submission #439457

# Submission time Handle Problem Language Result Execution time Memory
439457 2021-06-30T04:08:30 Z fcmalkcin Food Court (JOI21_foodcourt) C++17
68 / 100
429 ms 17652 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=1e5+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 7 ms 6092 KB Output is correct
2 Correct 10 ms 6092 KB Output is correct
3 Correct 9 ms 6092 KB Output is correct
4 Correct 9 ms 6092 KB Output is correct
5 Correct 8 ms 6092 KB Output is correct
6 Correct 7 ms 6092 KB Output is correct
7 Correct 8 ms 6092 KB Output is correct
8 Correct 10 ms 6064 KB Output is correct
9 Correct 8 ms 6092 KB Output is correct
10 Correct 9 ms 6064 KB Output is correct
11 Correct 8 ms 6092 KB Output is correct
12 Correct 8 ms 6092 KB Output is correct
13 Correct 8 ms 6060 KB Output is correct
14 Correct 9 ms 6092 KB Output is correct
15 Correct 8 ms 6092 KB Output is correct
16 Correct 10 ms 6164 KB Output is correct
17 Correct 8 ms 6036 KB Output is correct
18 Correct 8 ms 6100 KB Output is correct
19 Correct 7 ms 6092 KB Output is correct
20 Correct 8 ms 6156 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 6092 KB Output is correct
2 Correct 10 ms 6092 KB Output is correct
3 Correct 9 ms 6092 KB Output is correct
4 Correct 9 ms 6092 KB Output is correct
5 Correct 8 ms 6092 KB Output is correct
6 Correct 7 ms 6092 KB Output is correct
7 Correct 8 ms 6092 KB Output is correct
8 Correct 10 ms 6064 KB Output is correct
9 Correct 8 ms 6092 KB Output is correct
10 Correct 9 ms 6064 KB Output is correct
11 Correct 8 ms 6092 KB Output is correct
12 Correct 8 ms 6092 KB Output is correct
13 Correct 8 ms 6060 KB Output is correct
14 Correct 9 ms 6092 KB Output is correct
15 Correct 8 ms 6092 KB Output is correct
16 Correct 10 ms 6164 KB Output is correct
17 Correct 8 ms 6036 KB Output is correct
18 Correct 8 ms 6100 KB Output is correct
19 Correct 7 ms 6092 KB Output is correct
20 Correct 8 ms 6156 KB Output is correct
21 Correct 9 ms 6036 KB Output is correct
22 Correct 9 ms 6092 KB Output is correct
23 Correct 8 ms 6064 KB Output is correct
24 Correct 10 ms 6148 KB Output is correct
25 Correct 7 ms 6092 KB Output is correct
26 Correct 7 ms 6092 KB Output is correct
27 Correct 9 ms 6160 KB Output is correct
28 Correct 9 ms 6092 KB Output is correct
29 Correct 11 ms 6092 KB Output is correct
30 Correct 8 ms 6092 KB Output is correct
31 Correct 9 ms 6068 KB Output is correct
32 Correct 8 ms 6068 KB Output is correct
33 Correct 7 ms 6092 KB Output is correct
34 Correct 8 ms 6092 KB Output is correct
35 Correct 8 ms 6128 KB Output is correct
36 Correct 8 ms 6092 KB Output is correct
37 Correct 6 ms 6092 KB Output is correct
38 Correct 9 ms 6064 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 133 ms 16532 KB Output is correct
2 Correct 161 ms 16860 KB Output is correct
3 Correct 140 ms 16580 KB Output is correct
4 Correct 139 ms 16564 KB Output is correct
5 Correct 155 ms 16784 KB Output is correct
6 Correct 149 ms 16916 KB Output is correct
7 Correct 119 ms 15284 KB Output is correct
8 Correct 142 ms 15416 KB Output is correct
9 Correct 161 ms 16848 KB Output is correct
10 Correct 153 ms 16916 KB Output is correct
11 Correct 146 ms 16928 KB Output is correct
12 Correct 170 ms 16824 KB Output is correct
13 Correct 161 ms 16020 KB Output is correct
14 Correct 193 ms 16588 KB Output is correct
15 Correct 151 ms 17200 KB Output is correct
16 Correct 159 ms 17096 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 12 ms 11612 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 6092 KB Output is correct
2 Correct 10 ms 6092 KB Output is correct
3 Correct 9 ms 6092 KB Output is correct
4 Correct 9 ms 6092 KB Output is correct
5 Correct 8 ms 6092 KB Output is correct
6 Correct 7 ms 6092 KB Output is correct
7 Correct 8 ms 6092 KB Output is correct
8 Correct 10 ms 6064 KB Output is correct
9 Correct 8 ms 6092 KB Output is correct
10 Correct 9 ms 6064 KB Output is correct
11 Correct 8 ms 6092 KB Output is correct
12 Correct 8 ms 6092 KB Output is correct
13 Correct 8 ms 6060 KB Output is correct
14 Correct 9 ms 6092 KB Output is correct
15 Correct 8 ms 6092 KB Output is correct
16 Correct 10 ms 6164 KB Output is correct
17 Correct 8 ms 6036 KB Output is correct
18 Correct 8 ms 6100 KB Output is correct
19 Correct 7 ms 6092 KB Output is correct
20 Correct 8 ms 6156 KB Output is correct
21 Correct 133 ms 16532 KB Output is correct
22 Correct 161 ms 16860 KB Output is correct
23 Correct 140 ms 16580 KB Output is correct
24 Correct 139 ms 16564 KB Output is correct
25 Correct 155 ms 16784 KB Output is correct
26 Correct 149 ms 16916 KB Output is correct
27 Correct 119 ms 15284 KB Output is correct
28 Correct 142 ms 15416 KB Output is correct
29 Correct 161 ms 16848 KB Output is correct
30 Correct 153 ms 16916 KB Output is correct
31 Correct 146 ms 16928 KB Output is correct
32 Correct 170 ms 16824 KB Output is correct
33 Correct 161 ms 16020 KB Output is correct
34 Correct 193 ms 16588 KB Output is correct
35 Correct 151 ms 17200 KB Output is correct
36 Correct 159 ms 17096 KB Output is correct
37 Correct 298 ms 16000 KB Output is correct
38 Correct 201 ms 15744 KB Output is correct
39 Correct 138 ms 14772 KB Output is correct
40 Correct 176 ms 15156 KB Output is correct
41 Correct 301 ms 16728 KB Output is correct
42 Correct 290 ms 16696 KB Output is correct
43 Correct 322 ms 16676 KB Output is correct
44 Correct 284 ms 16680 KB Output is correct
45 Correct 275 ms 16680 KB Output is correct
46 Correct 289 ms 16660 KB Output is correct
47 Correct 246 ms 15504 KB Output is correct
48 Correct 305 ms 17092 KB Output is correct
49 Correct 173 ms 15360 KB Output is correct
50 Correct 222 ms 16072 KB Output is correct
51 Correct 249 ms 16808 KB Output is correct
52 Correct 245 ms 16788 KB Output is correct
53 Correct 122 ms 15920 KB Output is correct
54 Correct 153 ms 17092 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 356 ms 16204 KB Output is correct
2 Correct 413 ms 16644 KB Output is correct
3 Correct 399 ms 16720 KB Output is correct
4 Correct 297 ms 15212 KB Output is correct
5 Correct 357 ms 16068 KB Output is correct
6 Correct 429 ms 16836 KB Output is correct
7 Correct 277 ms 15132 KB Output is correct
8 Correct 253 ms 15096 KB Output is correct
9 Correct 378 ms 16180 KB Output is correct
10 Correct 259 ms 15556 KB Output is correct
11 Correct 384 ms 16680 KB Output is correct
12 Correct 412 ms 16704 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 6092 KB Output is correct
2 Correct 10 ms 6092 KB Output is correct
3 Correct 9 ms 6092 KB Output is correct
4 Correct 9 ms 6092 KB Output is correct
5 Correct 8 ms 6092 KB Output is correct
6 Correct 7 ms 6092 KB Output is correct
7 Correct 8 ms 6092 KB Output is correct
8 Correct 10 ms 6064 KB Output is correct
9 Correct 8 ms 6092 KB Output is correct
10 Correct 9 ms 6064 KB Output is correct
11 Correct 8 ms 6092 KB Output is correct
12 Correct 8 ms 6092 KB Output is correct
13 Correct 8 ms 6060 KB Output is correct
14 Correct 9 ms 6092 KB Output is correct
15 Correct 8 ms 6092 KB Output is correct
16 Correct 10 ms 6164 KB Output is correct
17 Correct 8 ms 6036 KB Output is correct
18 Correct 8 ms 6100 KB Output is correct
19 Correct 7 ms 6092 KB Output is correct
20 Correct 8 ms 6156 KB Output is correct
21 Correct 9 ms 6036 KB Output is correct
22 Correct 9 ms 6092 KB Output is correct
23 Correct 8 ms 6064 KB Output is correct
24 Correct 10 ms 6148 KB Output is correct
25 Correct 7 ms 6092 KB Output is correct
26 Correct 7 ms 6092 KB Output is correct
27 Correct 9 ms 6160 KB Output is correct
28 Correct 9 ms 6092 KB Output is correct
29 Correct 11 ms 6092 KB Output is correct
30 Correct 8 ms 6092 KB Output is correct
31 Correct 9 ms 6068 KB Output is correct
32 Correct 8 ms 6068 KB Output is correct
33 Correct 7 ms 6092 KB Output is correct
34 Correct 8 ms 6092 KB Output is correct
35 Correct 8 ms 6128 KB Output is correct
36 Correct 8 ms 6092 KB Output is correct
37 Correct 6 ms 6092 KB Output is correct
38 Correct 9 ms 6064 KB Output is correct
39 Correct 133 ms 16532 KB Output is correct
40 Correct 161 ms 16860 KB Output is correct
41 Correct 140 ms 16580 KB Output is correct
42 Correct 139 ms 16564 KB Output is correct
43 Correct 155 ms 16784 KB Output is correct
44 Correct 149 ms 16916 KB Output is correct
45 Correct 119 ms 15284 KB Output is correct
46 Correct 142 ms 15416 KB Output is correct
47 Correct 161 ms 16848 KB Output is correct
48 Correct 153 ms 16916 KB Output is correct
49 Correct 146 ms 16928 KB Output is correct
50 Correct 170 ms 16824 KB Output is correct
51 Correct 161 ms 16020 KB Output is correct
52 Correct 193 ms 16588 KB Output is correct
53 Correct 151 ms 17200 KB Output is correct
54 Correct 159 ms 17096 KB Output is correct
55 Correct 298 ms 16000 KB Output is correct
56 Correct 201 ms 15744 KB Output is correct
57 Correct 138 ms 14772 KB Output is correct
58 Correct 176 ms 15156 KB Output is correct
59 Correct 301 ms 16728 KB Output is correct
60 Correct 290 ms 16696 KB Output is correct
61 Correct 322 ms 16676 KB Output is correct
62 Correct 284 ms 16680 KB Output is correct
63 Correct 275 ms 16680 KB Output is correct
64 Correct 289 ms 16660 KB Output is correct
65 Correct 246 ms 15504 KB Output is correct
66 Correct 305 ms 17092 KB Output is correct
67 Correct 173 ms 15360 KB Output is correct
68 Correct 222 ms 16072 KB Output is correct
69 Correct 249 ms 16808 KB Output is correct
70 Correct 245 ms 16788 KB Output is correct
71 Correct 122 ms 15920 KB Output is correct
72 Correct 153 ms 17092 KB Output is correct
73 Correct 356 ms 16204 KB Output is correct
74 Correct 413 ms 16644 KB Output is correct
75 Correct 399 ms 16720 KB Output is correct
76 Correct 297 ms 15212 KB Output is correct
77 Correct 357 ms 16068 KB Output is correct
78 Correct 429 ms 16836 KB Output is correct
79 Correct 277 ms 15132 KB Output is correct
80 Correct 253 ms 15096 KB Output is correct
81 Correct 378 ms 16180 KB Output is correct
82 Correct 259 ms 15556 KB Output is correct
83 Correct 384 ms 16680 KB Output is correct
84 Correct 412 ms 16704 KB Output is correct
85 Correct 286 ms 16488 KB Output is correct
86 Correct 315 ms 16952 KB Output is correct
87 Correct 266 ms 16700 KB Output is correct
88 Correct 291 ms 17260 KB Output is correct
89 Correct 193 ms 15480 KB Output is correct
90 Correct 282 ms 17248 KB Output is correct
91 Correct 239 ms 16272 KB Output is correct
92 Correct 233 ms 16028 KB Output is correct
93 Correct 270 ms 17248 KB Output is correct
94 Correct 298 ms 17220 KB Output is correct
95 Correct 287 ms 17280 KB Output is correct
96 Correct 289 ms 17276 KB Output is correct
97 Correct 281 ms 17176 KB Output is correct
98 Correct 258 ms 16492 KB Output is correct
99 Correct 244 ms 16040 KB Output is correct
100 Correct 258 ms 16260 KB Output is correct
101 Correct 315 ms 17652 KB Output is correct
102 Correct 236 ms 17524 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 6092 KB Output is correct
2 Correct 10 ms 6092 KB Output is correct
3 Correct 9 ms 6092 KB Output is correct
4 Correct 9 ms 6092 KB Output is correct
5 Correct 8 ms 6092 KB Output is correct
6 Correct 7 ms 6092 KB Output is correct
7 Correct 8 ms 6092 KB Output is correct
8 Correct 10 ms 6064 KB Output is correct
9 Correct 8 ms 6092 KB Output is correct
10 Correct 9 ms 6064 KB Output is correct
11 Correct 8 ms 6092 KB Output is correct
12 Correct 8 ms 6092 KB Output is correct
13 Correct 8 ms 6060 KB Output is correct
14 Correct 9 ms 6092 KB Output is correct
15 Correct 8 ms 6092 KB Output is correct
16 Correct 10 ms 6164 KB Output is correct
17 Correct 8 ms 6036 KB Output is correct
18 Correct 8 ms 6100 KB Output is correct
19 Correct 7 ms 6092 KB Output is correct
20 Correct 8 ms 6156 KB Output is correct
21 Correct 9 ms 6036 KB Output is correct
22 Correct 9 ms 6092 KB Output is correct
23 Correct 8 ms 6064 KB Output is correct
24 Correct 10 ms 6148 KB Output is correct
25 Correct 7 ms 6092 KB Output is correct
26 Correct 7 ms 6092 KB Output is correct
27 Correct 9 ms 6160 KB Output is correct
28 Correct 9 ms 6092 KB Output is correct
29 Correct 11 ms 6092 KB Output is correct
30 Correct 8 ms 6092 KB Output is correct
31 Correct 9 ms 6068 KB Output is correct
32 Correct 8 ms 6068 KB Output is correct
33 Correct 7 ms 6092 KB Output is correct
34 Correct 8 ms 6092 KB Output is correct
35 Correct 8 ms 6128 KB Output is correct
36 Correct 8 ms 6092 KB Output is correct
37 Correct 6 ms 6092 KB Output is correct
38 Correct 9 ms 6064 KB Output is correct
39 Correct 133 ms 16532 KB Output is correct
40 Correct 161 ms 16860 KB Output is correct
41 Correct 140 ms 16580 KB Output is correct
42 Correct 139 ms 16564 KB Output is correct
43 Correct 155 ms 16784 KB Output is correct
44 Correct 149 ms 16916 KB Output is correct
45 Correct 119 ms 15284 KB Output is correct
46 Correct 142 ms 15416 KB Output is correct
47 Correct 161 ms 16848 KB Output is correct
48 Correct 153 ms 16916 KB Output is correct
49 Correct 146 ms 16928 KB Output is correct
50 Correct 170 ms 16824 KB Output is correct
51 Correct 161 ms 16020 KB Output is correct
52 Correct 193 ms 16588 KB Output is correct
53 Correct 151 ms 17200 KB Output is correct
54 Correct 159 ms 17096 KB Output is correct
55 Runtime error 12 ms 11612 KB Execution killed with signal 11
56 Halted 0 ms 0 KB -