Submission #963573

# Submission time Handle Problem Language Result Execution time Memory
963573 2024-04-15T11:07:15 Z HoriaHaivas Food Court (JOI21_foodcourt) C++14
68 / 100
495 ms 182420 KB
/*
    "care a facut teste cu Lattice reduction attack e ciudat"
    "linistiti va putin"
    - 2023 -
*/
#include<bits/stdc++.h>
#define debug(x) cerr << #x << " " << x << "\n"
#define debugs(x) cerr << #x << " " << x << " "
#pragma GCC optimize("Ofast")
#define int long long

using namespace std;

struct query
{
    int type;
    int l;
    int r;
    int k;
    int c;
    int a;
    int b;
    int time;
    int ans;
};
int q;
vector<query> add[250001];
vector<query> rem[250001];
vector<query> answer[250001];
query qq[250001];

struct Node
{
    int minval;
    int lazy;
};
Node aint[1000001];

void prop(int val)
{
    if (aint[val].lazy==0)
        return;
    aint[val].minval+=aint[val].lazy;
    if (val*2+1<1000001)
    {
        aint[val*2].lazy+=aint[val].lazy;
        aint[val*2+1].lazy+=aint[val].lazy;
    }
    aint[val].lazy=0;
}

void lazy_update(int l, int r, int val, int qa, int qb, int x)
{
    prop(val);
    if (qa<=l && r<=qb)
    {
        aint[val].lazy+=x;
        return;
    }
    int mid;
    mid=(l+r)/2;
    if (qa<=mid)
    lazy_update(l,mid,val*2,qa,qb,x);
    if (qb>mid)
    lazy_update(mid+1,r,val*2+1,qa,qb,x);
    prop(val*2);
    prop(val*2+1);
    aint[val].minval=min(aint[val*2].minval,aint[val*2+1].minval);
}

int aint_query(int l, int r, int val, int qa, int qb)
{
    prop(val);
    if (qa<=l && r<=qb)
    {
        return aint[val].minval;
    }
    int mid,ans;
    mid=(l+r)/2;
    ans=1e18;
    if (qa<=mid)
    ans=min(ans,aint_query(l,mid,val*2,qa,qb));
    if (qb>mid)
    ans=min(ans,aint_query(mid+1,r,val*2+1,qa,qb));
    return ans;
}

int aib[250001];

void aib_update(int index, int delta)
{
    while (index<=q)
    {
        aib[index]+=delta;
        index+=index&(-index);
    }
}

int aib_query(int index)
{
    int ans=0;
    while (index>0)
    {
         ans+=aib[index];
         index-=index&(-index);
    }
    return ans;
}

int kth(int k)
{
    int r,pas;
    r=0;
    pas=(1<<18);
    while (pas)
    {
        if (r+pas<=q && aib_query(r+pas)<k)
            r+=pas;
        pas=pas/2;
    }
    return r+1;
}

signed main()
{
    ifstream fin("secvp.in");
    ofstream fout("secvp.out");
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n,m,i,j,actually_left,actualb;
    cin >> n >> m >> q;
    for (i=1;i<=q;i++)
    {
         cin >> qq[i].type;
         qq[i].time=i;
         if (qq[i].type==1)
         {
             cin >> qq[i].l >> qq[i].r >> qq[i].c >> qq[i].k;
             add[qq[i].l].push_back(qq[i]);
             rem[qq[i].r+1].push_back(qq[i]);
         }
         else if (qq[i].type==2)
         {
             cin >> qq[i].l >> qq[i].r >> qq[i].k;
             add[qq[i].l].push_back(qq[i]);
             rem[qq[i].r+1].push_back(qq[i]);
         }
         else if (qq[i].type==3)
         {
             cin >> qq[i].a >> qq[i].b;
             answer[qq[i].a].push_back(qq[i]);
         }
    }
    for (i=1;i<=n;i++)
    {
         for (auto x : rem[i])
         {
              if (x.type==1)
              {
                  aib_update(x.time,-x.k);
                  lazy_update(1,q,1,x.time,q,-x.k);
              }
              else
              {
                  lazy_update(1,q,1,x.time,q,x.k);
              }
         }
         for (auto x : add[i])
         {
              if (x.type==1)
              {
                  aib_update(x.time,x.k);
                  lazy_update(1,q,1,x.time,q,x.k);
              }
              else
              {
                  lazy_update(1,q,1,x.time,q,-x.k);
              }
         }
         for (auto x : answer[i])
         {
              actually_left=aib_query(x.time)-(aint_query(1,q,1,x.time,x.time)-min(1LL*0,aint_query(1,q,1,1,x.time)));
              actualb=x.b+actually_left;
              if (kth(actualb)<=x.time)
              qq[x.time].ans=qq[kth(actualb)].c;
              else
              qq[x.time].ans=0;
         }
    }
    for (i=1;i<=q;i++)
    {
         if (qq[i].type==3)
         {
             cout << qq[i].ans << "\n";
         }
    }
}

Compilation message

foodcourt.cpp: In function 'int main()':
foodcourt.cpp:131:15: warning: unused variable 'j' [-Wunused-variable]
  131 |     int n,m,i,j,actually_left,actualb;
      |               ^
# Verdict Execution time Memory Grader output
1 Correct 8 ms 20572 KB Output is correct
2 Correct 8 ms 20744 KB Output is correct
3 Correct 6 ms 20572 KB Output is correct
4 Correct 7 ms 20572 KB Output is correct
5 Correct 6 ms 20828 KB Output is correct
6 Correct 6 ms 20572 KB Output is correct
7 Correct 7 ms 20572 KB Output is correct
8 Correct 6 ms 20572 KB Output is correct
9 Correct 7 ms 20568 KB Output is correct
10 Correct 7 ms 20824 KB Output is correct
11 Correct 7 ms 20712 KB Output is correct
12 Correct 8 ms 20572 KB Output is correct
13 Correct 7 ms 20752 KB Output is correct
14 Correct 6 ms 21080 KB Output is correct
15 Correct 6 ms 20572 KB Output is correct
16 Correct 7 ms 20828 KB Output is correct
17 Correct 6 ms 20572 KB Output is correct
18 Correct 7 ms 20572 KB Output is correct
19 Correct 6 ms 20564 KB Output is correct
20 Correct 7 ms 20572 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 20572 KB Output is correct
2 Correct 8 ms 20744 KB Output is correct
3 Correct 6 ms 20572 KB Output is correct
4 Correct 7 ms 20572 KB Output is correct
5 Correct 6 ms 20828 KB Output is correct
6 Correct 6 ms 20572 KB Output is correct
7 Correct 7 ms 20572 KB Output is correct
8 Correct 6 ms 20572 KB Output is correct
9 Correct 7 ms 20568 KB Output is correct
10 Correct 7 ms 20824 KB Output is correct
11 Correct 7 ms 20712 KB Output is correct
12 Correct 8 ms 20572 KB Output is correct
13 Correct 7 ms 20752 KB Output is correct
14 Correct 6 ms 21080 KB Output is correct
15 Correct 6 ms 20572 KB Output is correct
16 Correct 7 ms 20828 KB Output is correct
17 Correct 6 ms 20572 KB Output is correct
18 Correct 7 ms 20572 KB Output is correct
19 Correct 6 ms 20564 KB Output is correct
20 Correct 7 ms 20572 KB Output is correct
21 Correct 7 ms 20568 KB Output is correct
22 Correct 7 ms 20780 KB Output is correct
23 Correct 7 ms 20572 KB Output is correct
24 Correct 7 ms 20796 KB Output is correct
25 Correct 6 ms 20776 KB Output is correct
26 Correct 6 ms 20828 KB Output is correct
27 Correct 8 ms 20572 KB Output is correct
28 Correct 6 ms 20572 KB Output is correct
29 Correct 7 ms 20572 KB Output is correct
30 Correct 7 ms 20572 KB Output is correct
31 Correct 7 ms 20572 KB Output is correct
32 Correct 7 ms 20568 KB Output is correct
33 Correct 6 ms 20824 KB Output is correct
34 Correct 6 ms 20824 KB Output is correct
35 Correct 7 ms 20572 KB Output is correct
36 Correct 6 ms 20824 KB Output is correct
37 Correct 6 ms 20568 KB Output is correct
38 Correct 6 ms 20572 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 98 ms 38484 KB Output is correct
2 Correct 80 ms 39004 KB Output is correct
3 Correct 92 ms 38772 KB Output is correct
4 Correct 83 ms 38620 KB Output is correct
5 Correct 83 ms 39004 KB Output is correct
6 Correct 81 ms 38992 KB Output is correct
7 Correct 40 ms 38616 KB Output is correct
8 Correct 41 ms 40016 KB Output is correct
9 Correct 76 ms 38996 KB Output is correct
10 Correct 79 ms 39140 KB Output is correct
11 Correct 80 ms 39228 KB Output is correct
12 Correct 99 ms 39184 KB Output is correct
13 Correct 68 ms 37224 KB Output is correct
14 Correct 87 ms 38740 KB Output is correct
15 Correct 82 ms 39908 KB Output is correct
16 Correct 87 ms 39884 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 391 ms 89716 KB Output is correct
2 Correct 349 ms 77776 KB Output is correct
3 Runtime error 495 ms 182420 KB Execution killed with signal 6
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 20572 KB Output is correct
2 Correct 8 ms 20744 KB Output is correct
3 Correct 6 ms 20572 KB Output is correct
4 Correct 7 ms 20572 KB Output is correct
5 Correct 6 ms 20828 KB Output is correct
6 Correct 6 ms 20572 KB Output is correct
7 Correct 7 ms 20572 KB Output is correct
8 Correct 6 ms 20572 KB Output is correct
9 Correct 7 ms 20568 KB Output is correct
10 Correct 7 ms 20824 KB Output is correct
11 Correct 7 ms 20712 KB Output is correct
12 Correct 8 ms 20572 KB Output is correct
13 Correct 7 ms 20752 KB Output is correct
14 Correct 6 ms 21080 KB Output is correct
15 Correct 6 ms 20572 KB Output is correct
16 Correct 7 ms 20828 KB Output is correct
17 Correct 6 ms 20572 KB Output is correct
18 Correct 7 ms 20572 KB Output is correct
19 Correct 6 ms 20564 KB Output is correct
20 Correct 7 ms 20572 KB Output is correct
21 Correct 98 ms 38484 KB Output is correct
22 Correct 80 ms 39004 KB Output is correct
23 Correct 92 ms 38772 KB Output is correct
24 Correct 83 ms 38620 KB Output is correct
25 Correct 83 ms 39004 KB Output is correct
26 Correct 81 ms 38992 KB Output is correct
27 Correct 40 ms 38616 KB Output is correct
28 Correct 41 ms 40016 KB Output is correct
29 Correct 76 ms 38996 KB Output is correct
30 Correct 79 ms 39140 KB Output is correct
31 Correct 80 ms 39228 KB Output is correct
32 Correct 99 ms 39184 KB Output is correct
33 Correct 68 ms 37224 KB Output is correct
34 Correct 87 ms 38740 KB Output is correct
35 Correct 82 ms 39908 KB Output is correct
36 Correct 87 ms 39884 KB Output is correct
37 Correct 82 ms 37088 KB Output is correct
38 Correct 73 ms 36000 KB Output is correct
39 Correct 35 ms 37884 KB Output is correct
40 Correct 49 ms 41000 KB Output is correct
41 Correct 80 ms 38984 KB Output is correct
42 Correct 119 ms 39336 KB Output is correct
43 Correct 82 ms 39248 KB Output is correct
44 Correct 81 ms 39200 KB Output is correct
45 Correct 90 ms 39312 KB Output is correct
46 Correct 123 ms 39316 KB Output is correct
47 Correct 56 ms 38432 KB Output is correct
48 Correct 79 ms 41832 KB Output is correct
49 Correct 64 ms 34860 KB Output is correct
50 Correct 84 ms 37180 KB Output is correct
51 Correct 90 ms 39540 KB Output is correct
52 Correct 102 ms 39504 KB Output is correct
53 Correct 75 ms 36168 KB Output is correct
54 Correct 83 ms 39884 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 101 ms 36848 KB Output is correct
2 Correct 93 ms 38068 KB Output is correct
3 Correct 86 ms 38212 KB Output is correct
4 Correct 65 ms 33908 KB Output is correct
5 Correct 95 ms 36380 KB Output is correct
6 Correct 86 ms 38452 KB Output is correct
7 Correct 45 ms 35536 KB Output is correct
8 Correct 43 ms 35836 KB Output is correct
9 Correct 62 ms 37624 KB Output is correct
10 Correct 53 ms 35216 KB Output is correct
11 Correct 82 ms 39252 KB Output is correct
12 Correct 82 ms 39240 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 20572 KB Output is correct
2 Correct 8 ms 20744 KB Output is correct
3 Correct 6 ms 20572 KB Output is correct
4 Correct 7 ms 20572 KB Output is correct
5 Correct 6 ms 20828 KB Output is correct
6 Correct 6 ms 20572 KB Output is correct
7 Correct 7 ms 20572 KB Output is correct
8 Correct 6 ms 20572 KB Output is correct
9 Correct 7 ms 20568 KB Output is correct
10 Correct 7 ms 20824 KB Output is correct
11 Correct 7 ms 20712 KB Output is correct
12 Correct 8 ms 20572 KB Output is correct
13 Correct 7 ms 20752 KB Output is correct
14 Correct 6 ms 21080 KB Output is correct
15 Correct 6 ms 20572 KB Output is correct
16 Correct 7 ms 20828 KB Output is correct
17 Correct 6 ms 20572 KB Output is correct
18 Correct 7 ms 20572 KB Output is correct
19 Correct 6 ms 20564 KB Output is correct
20 Correct 7 ms 20572 KB Output is correct
21 Correct 7 ms 20568 KB Output is correct
22 Correct 7 ms 20780 KB Output is correct
23 Correct 7 ms 20572 KB Output is correct
24 Correct 7 ms 20796 KB Output is correct
25 Correct 6 ms 20776 KB Output is correct
26 Correct 6 ms 20828 KB Output is correct
27 Correct 8 ms 20572 KB Output is correct
28 Correct 6 ms 20572 KB Output is correct
29 Correct 7 ms 20572 KB Output is correct
30 Correct 7 ms 20572 KB Output is correct
31 Correct 7 ms 20572 KB Output is correct
32 Correct 7 ms 20568 KB Output is correct
33 Correct 6 ms 20824 KB Output is correct
34 Correct 6 ms 20824 KB Output is correct
35 Correct 7 ms 20572 KB Output is correct
36 Correct 6 ms 20824 KB Output is correct
37 Correct 6 ms 20568 KB Output is correct
38 Correct 6 ms 20572 KB Output is correct
39 Correct 98 ms 38484 KB Output is correct
40 Correct 80 ms 39004 KB Output is correct
41 Correct 92 ms 38772 KB Output is correct
42 Correct 83 ms 38620 KB Output is correct
43 Correct 83 ms 39004 KB Output is correct
44 Correct 81 ms 38992 KB Output is correct
45 Correct 40 ms 38616 KB Output is correct
46 Correct 41 ms 40016 KB Output is correct
47 Correct 76 ms 38996 KB Output is correct
48 Correct 79 ms 39140 KB Output is correct
49 Correct 80 ms 39228 KB Output is correct
50 Correct 99 ms 39184 KB Output is correct
51 Correct 68 ms 37224 KB Output is correct
52 Correct 87 ms 38740 KB Output is correct
53 Correct 82 ms 39908 KB Output is correct
54 Correct 87 ms 39884 KB Output is correct
55 Correct 82 ms 37088 KB Output is correct
56 Correct 73 ms 36000 KB Output is correct
57 Correct 35 ms 37884 KB Output is correct
58 Correct 49 ms 41000 KB Output is correct
59 Correct 80 ms 38984 KB Output is correct
60 Correct 119 ms 39336 KB Output is correct
61 Correct 82 ms 39248 KB Output is correct
62 Correct 81 ms 39200 KB Output is correct
63 Correct 90 ms 39312 KB Output is correct
64 Correct 123 ms 39316 KB Output is correct
65 Correct 56 ms 38432 KB Output is correct
66 Correct 79 ms 41832 KB Output is correct
67 Correct 64 ms 34860 KB Output is correct
68 Correct 84 ms 37180 KB Output is correct
69 Correct 90 ms 39540 KB Output is correct
70 Correct 102 ms 39504 KB Output is correct
71 Correct 75 ms 36168 KB Output is correct
72 Correct 83 ms 39884 KB Output is correct
73 Correct 101 ms 36848 KB Output is correct
74 Correct 93 ms 38068 KB Output is correct
75 Correct 86 ms 38212 KB Output is correct
76 Correct 65 ms 33908 KB Output is correct
77 Correct 95 ms 36380 KB Output is correct
78 Correct 86 ms 38452 KB Output is correct
79 Correct 45 ms 35536 KB Output is correct
80 Correct 43 ms 35836 KB Output is correct
81 Correct 62 ms 37624 KB Output is correct
82 Correct 53 ms 35216 KB Output is correct
83 Correct 82 ms 39252 KB Output is correct
84 Correct 82 ms 39240 KB Output is correct
85 Correct 94 ms 37752 KB Output is correct
86 Correct 103 ms 39092 KB Output is correct
87 Correct 86 ms 37808 KB Output is correct
88 Correct 95 ms 39820 KB Output is correct
89 Correct 56 ms 34360 KB Output is correct
90 Correct 100 ms 39840 KB Output is correct
91 Correct 75 ms 37108 KB Output is correct
92 Correct 64 ms 36336 KB Output is correct
93 Correct 92 ms 39764 KB Output is correct
94 Correct 88 ms 39576 KB Output is correct
95 Correct 90 ms 39600 KB Output is correct
96 Correct 85 ms 39824 KB Output is correct
97 Correct 119 ms 39876 KB Output is correct
98 Correct 83 ms 37468 KB Output is correct
99 Correct 52 ms 37960 KB Output is correct
100 Correct 59 ms 38072 KB Output is correct
101 Correct 91 ms 42260 KB Output is correct
102 Correct 77 ms 39764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 20572 KB Output is correct
2 Correct 8 ms 20744 KB Output is correct
3 Correct 6 ms 20572 KB Output is correct
4 Correct 7 ms 20572 KB Output is correct
5 Correct 6 ms 20828 KB Output is correct
6 Correct 6 ms 20572 KB Output is correct
7 Correct 7 ms 20572 KB Output is correct
8 Correct 6 ms 20572 KB Output is correct
9 Correct 7 ms 20568 KB Output is correct
10 Correct 7 ms 20824 KB Output is correct
11 Correct 7 ms 20712 KB Output is correct
12 Correct 8 ms 20572 KB Output is correct
13 Correct 7 ms 20752 KB Output is correct
14 Correct 6 ms 21080 KB Output is correct
15 Correct 6 ms 20572 KB Output is correct
16 Correct 7 ms 20828 KB Output is correct
17 Correct 6 ms 20572 KB Output is correct
18 Correct 7 ms 20572 KB Output is correct
19 Correct 6 ms 20564 KB Output is correct
20 Correct 7 ms 20572 KB Output is correct
21 Correct 7 ms 20568 KB Output is correct
22 Correct 7 ms 20780 KB Output is correct
23 Correct 7 ms 20572 KB Output is correct
24 Correct 7 ms 20796 KB Output is correct
25 Correct 6 ms 20776 KB Output is correct
26 Correct 6 ms 20828 KB Output is correct
27 Correct 8 ms 20572 KB Output is correct
28 Correct 6 ms 20572 KB Output is correct
29 Correct 7 ms 20572 KB Output is correct
30 Correct 7 ms 20572 KB Output is correct
31 Correct 7 ms 20572 KB Output is correct
32 Correct 7 ms 20568 KB Output is correct
33 Correct 6 ms 20824 KB Output is correct
34 Correct 6 ms 20824 KB Output is correct
35 Correct 7 ms 20572 KB Output is correct
36 Correct 6 ms 20824 KB Output is correct
37 Correct 6 ms 20568 KB Output is correct
38 Correct 6 ms 20572 KB Output is correct
39 Correct 98 ms 38484 KB Output is correct
40 Correct 80 ms 39004 KB Output is correct
41 Correct 92 ms 38772 KB Output is correct
42 Correct 83 ms 38620 KB Output is correct
43 Correct 83 ms 39004 KB Output is correct
44 Correct 81 ms 38992 KB Output is correct
45 Correct 40 ms 38616 KB Output is correct
46 Correct 41 ms 40016 KB Output is correct
47 Correct 76 ms 38996 KB Output is correct
48 Correct 79 ms 39140 KB Output is correct
49 Correct 80 ms 39228 KB Output is correct
50 Correct 99 ms 39184 KB Output is correct
51 Correct 68 ms 37224 KB Output is correct
52 Correct 87 ms 38740 KB Output is correct
53 Correct 82 ms 39908 KB Output is correct
54 Correct 87 ms 39884 KB Output is correct
55 Correct 391 ms 89716 KB Output is correct
56 Correct 349 ms 77776 KB Output is correct
57 Runtime error 495 ms 182420 KB Execution killed with signal 6
58 Halted 0 ms 0 KB -