답안 #564337

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
564337 2022-05-19T02:27:58 Z fcmalkcin Ants and Sugar (JOI22_sugar) C++17
100 / 100
1816 ms 128164 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"
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

const ll maxn=5e5+10;
const ll mod=1e9+7  ;
const ll base=3e18;

ll t[maxn];
ll x[maxn];
ll a[maxn];
struct tk
{
    ll dp[2][2];
    ll la;
    ll la1;
    tk()
    {
        la=0;
        la1=0;
        for (int t=0; t<=1; t++)
            for (int t1=0; t1<=1; t1++)
                dp[t][t1]=-base;
    }
};
tk st[4*maxn];
void modify(ll id,ll val,ll val1)
{
    st[id].dp[0][0]-=val;
    st[id].dp[1][1]+=(val+val1);
    st[id].dp[0][1]+=val1;
    st[id].dp[1][0]+=val1;
    st[id].la+=val;
    st[id].la1+=val1;
}
void dosth(ll id)
{
    modify(id*2,st[id].la,st[id].la1);
    modify(id*2+1,st[id].la,st[id].la1);
    st[id].la=0;
    st[id].la1=0;
}
tk mer(tk a,tk b)
{
    tk c;
    for (int l=0; l<=1; l++)
    {
        for (int r=0; r<=1; r++)
        {
            ll l1=1-r;
            for (int r1=0; r1<=1; r1++)
            {
                c.dp[l][r1]=max(max(max(a.dp[l][r1],b.dp[l][r1]),c.dp[l][r1]),a.dp[l][r]+b.dp[l1][r1]);
            }
        }
    }
    return c;
}
void update1(ll id,ll left,ll right,ll x,ll y,ll val,ll val1)
{
    // if (left==1&&right==4) cout <<x<<" "<<y<<" "<<val<<" "<<val1<<" wtf"<<endl;
    if (x>right||y<left)
        return ;
    if (x<=left&&y>=right)
    {
        modify(id,val,val1);
        return ;
    }
    dosth(id);
    ll mid=(left+right)/2;
    update1(id*2,left,mid,x,y,val,val1);
    update1(id*2+1,mid+1,right,x,y,val,val1);
    st[id]=mer(st[id*2],st[id*2+1]);
}
void build(ll id,ll left,ll right)
{
    if (left==right)
    {
       st[id].dp[0][1]=0;
       st[id].dp[0][0]=0;
       st[id].dp[1][1]=0;
        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 get(ll id,ll left,ll right)
{
// for (int t=0;t<=1;t++) for (int t1=0;t1<=1;t1++) cout <<st[id].dp[t][t1]<<" "<<id<<" "<<t<<" "<<t1<<" chk2"<<endl;
    if (left==right)
        return ;
    dosth(id);
    ll mid=(left+right)/2;
    get(id*2,left,mid);
    get(id*2+1,mid+1,right);
  //  st[id]=mer(st[id*2],st[id*2+1]);
    /*auto p=mer(st[id*2],st[id*2+1]);
    for (int t=0;t<=1;t++)
    {
        for (int t1=0;t1<=1;t1++)
        {

        }
    }*/
}
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);
    }
    ll q, l;
    cin>> q>> l;
    vector<ll> vt;
    for (int i=1; i<=q; i++)
    {
        cin>> t[i]>> x[i]>> a[i];
        vt.pb(x[i]);
    }
    sort(vt.begin(),vt.end());
    vt.resize(unique(vt.begin(),vt.end())-vt.begin());
    ll len=vt.size();
    build(1,1,len);
    ll cnt=0;
    for (int i=1; i<=q; i++)
    {
        if (t[i]==1)
        {
            cnt+=a[i];
            ll pos=lower_bound(vt.begin(),vt.end(),x[i]+1)-vt.begin()+1;
            update1(1,1,len,pos,len,a[i],0);
            pos=lower_bound(vt.begin(),vt.end(),x[i])-vt.begin()+1;
            update1(1,1,len,pos,pos,0,a[i]);

        }
        else
        {
            ll pos=lower_bound(vt.begin(),vt.end(),x[i]+l+1)-vt.begin()+1;
            update1(1,1,len,pos,len,-a[i],0);
            /*if (i==2)
            {
                cout <<pos<<" "<<len<<" wtf"<<endl;
            }*/

            ll rt=upper_bound(vt.begin(),vt.end(),x[i]+l)-vt.begin();
            ll lf=lower_bound(vt.begin(),vt.end(),x[i]-l)-vt.begin()+1;
            //    cout <<lf<<" "<<rt<<" "<<vt.size()<<" "<<x[i]+l+1<<" chk1"<<endl;
            update1(1,1,len,lf,rt,0,-a[i]);
        }
        /*get(1,1,len);
        if (i==3)
        {
            cout <<st[2].dp[0][0]<<" "<<st[3].dp[1][1]<<" chkwtf"<<endl;
            for (int h=4; h<=7; h++)
            {
                for (int t=0; t<=1; t++)
                    for (int t1=0; t1<=1; t1++)
                        cout <<st[h].dp[t][t1]<<" "<<h-3<<" "<<t<<" "<<t1<<" wtf3"<<endl;
            }
        }*/
        ll res=0;
        res=max(res,st[1].dp[0][1]);
        //   cout <<st[1].dp[0][1]<<" wtf"<<endl;
        /*if (i==3)
        {

            cout <<cnt<<" "<<res<<" chk1"<<endl;
        }*/
        // auto p=mer(st[2],st[3]);
        // cout <<p.dp[0][1]<<" wtfchk3"<<endl;
        cout <<cnt-res<<endl;
    }
}

Compilation message

sugar.cpp: In function 'int main()':
sugar.cpp:122:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  122 |         freopen("test.inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
sugar.cpp:123:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  123 |         freopen("test.out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 46 ms 94264 KB Output is correct
2 Correct 42 ms 94244 KB Output is correct
3 Correct 48 ms 94144 KB Output is correct
4 Correct 42 ms 94168 KB Output is correct
5 Correct 42 ms 94180 KB Output is correct
6 Correct 46 ms 94348 KB Output is correct
7 Correct 55 ms 94288 KB Output is correct
8 Correct 43 ms 94252 KB Output is correct
9 Correct 44 ms 94324 KB Output is correct
10 Correct 45 ms 94412 KB Output is correct
11 Correct 54 ms 94480 KB Output is correct
12 Correct 58 ms 94480 KB Output is correct
13 Correct 44 ms 94392 KB Output is correct
14 Correct 44 ms 94412 KB Output is correct
15 Correct 43 ms 94412 KB Output is correct
16 Correct 47 ms 94496 KB Output is correct
17 Correct 52 ms 94412 KB Output is correct
18 Correct 46 ms 94412 KB Output is correct
19 Correct 45 ms 94484 KB Output is correct
20 Correct 46 ms 94412 KB Output is correct
21 Correct 54 ms 94412 KB Output is correct
22 Correct 46 ms 94532 KB Output is correct
23 Correct 47 ms 94412 KB Output is correct
24 Correct 46 ms 94408 KB Output is correct
25 Correct 53 ms 94380 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 41 ms 94212 KB Output is correct
2 Correct 46 ms 94244 KB Output is correct
3 Correct 41 ms 94200 KB Output is correct
4 Correct 1022 ms 117236 KB Output is correct
5 Correct 575 ms 109448 KB Output is correct
6 Correct 1182 ms 121280 KB Output is correct
7 Correct 542 ms 109616 KB Output is correct
8 Correct 1643 ms 125404 KB Output is correct
9 Correct 1076 ms 126976 KB Output is correct
10 Correct 1516 ms 126480 KB Output is correct
11 Correct 1090 ms 125584 KB Output is correct
12 Correct 509 ms 107308 KB Output is correct
13 Correct 664 ms 111956 KB Output is correct
14 Correct 1198 ms 123196 KB Output is correct
15 Correct 1085 ms 123192 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 49 ms 94156 KB Output is correct
2 Correct 494 ms 107080 KB Output is correct
3 Correct 670 ms 111868 KB Output is correct
4 Correct 1090 ms 122972 KB Output is correct
5 Correct 1102 ms 123028 KB Output is correct
6 Correct 1143 ms 117564 KB Output is correct
7 Correct 102 ms 96188 KB Output is correct
8 Correct 558 ms 106012 KB Output is correct
9 Correct 863 ms 111696 KB Output is correct
10 Correct 1549 ms 124672 KB Output is correct
11 Correct 1531 ms 124572 KB Output is correct
12 Correct 1510 ms 124456 KB Output is correct
13 Correct 1509 ms 124612 KB Output is correct
14 Correct 1581 ms 124832 KB Output is correct
15 Correct 1553 ms 124312 KB Output is correct
16 Correct 1640 ms 124780 KB Output is correct
17 Correct 1645 ms 124528 KB Output is correct
18 Correct 1649 ms 124748 KB Output is correct
19 Correct 1646 ms 124756 KB Output is correct
20 Correct 1816 ms 124204 KB Output is correct
21 Correct 1748 ms 124848 KB Output is correct
22 Correct 1741 ms 124476 KB Output is correct
23 Correct 1607 ms 124772 KB Output is correct
24 Correct 1069 ms 124580 KB Output is correct
25 Correct 1294 ms 124544 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 46 ms 94264 KB Output is correct
2 Correct 42 ms 94244 KB Output is correct
3 Correct 48 ms 94144 KB Output is correct
4 Correct 42 ms 94168 KB Output is correct
5 Correct 42 ms 94180 KB Output is correct
6 Correct 46 ms 94348 KB Output is correct
7 Correct 55 ms 94288 KB Output is correct
8 Correct 43 ms 94252 KB Output is correct
9 Correct 44 ms 94324 KB Output is correct
10 Correct 45 ms 94412 KB Output is correct
11 Correct 54 ms 94480 KB Output is correct
12 Correct 58 ms 94480 KB Output is correct
13 Correct 44 ms 94392 KB Output is correct
14 Correct 44 ms 94412 KB Output is correct
15 Correct 43 ms 94412 KB Output is correct
16 Correct 47 ms 94496 KB Output is correct
17 Correct 52 ms 94412 KB Output is correct
18 Correct 46 ms 94412 KB Output is correct
19 Correct 45 ms 94484 KB Output is correct
20 Correct 46 ms 94412 KB Output is correct
21 Correct 54 ms 94412 KB Output is correct
22 Correct 46 ms 94532 KB Output is correct
23 Correct 47 ms 94412 KB Output is correct
24 Correct 46 ms 94408 KB Output is correct
25 Correct 53 ms 94380 KB Output is correct
26 Correct 41 ms 94212 KB Output is correct
27 Correct 46 ms 94244 KB Output is correct
28 Correct 41 ms 94200 KB Output is correct
29 Correct 1022 ms 117236 KB Output is correct
30 Correct 575 ms 109448 KB Output is correct
31 Correct 1182 ms 121280 KB Output is correct
32 Correct 542 ms 109616 KB Output is correct
33 Correct 1643 ms 125404 KB Output is correct
34 Correct 1076 ms 126976 KB Output is correct
35 Correct 1516 ms 126480 KB Output is correct
36 Correct 1090 ms 125584 KB Output is correct
37 Correct 509 ms 107308 KB Output is correct
38 Correct 664 ms 111956 KB Output is correct
39 Correct 1198 ms 123196 KB Output is correct
40 Correct 1085 ms 123192 KB Output is correct
41 Correct 49 ms 94156 KB Output is correct
42 Correct 494 ms 107080 KB Output is correct
43 Correct 670 ms 111868 KB Output is correct
44 Correct 1090 ms 122972 KB Output is correct
45 Correct 1102 ms 123028 KB Output is correct
46 Correct 1143 ms 117564 KB Output is correct
47 Correct 102 ms 96188 KB Output is correct
48 Correct 558 ms 106012 KB Output is correct
49 Correct 863 ms 111696 KB Output is correct
50 Correct 1549 ms 124672 KB Output is correct
51 Correct 1531 ms 124572 KB Output is correct
52 Correct 1510 ms 124456 KB Output is correct
53 Correct 1509 ms 124612 KB Output is correct
54 Correct 1581 ms 124832 KB Output is correct
55 Correct 1553 ms 124312 KB Output is correct
56 Correct 1640 ms 124780 KB Output is correct
57 Correct 1645 ms 124528 KB Output is correct
58 Correct 1649 ms 124748 KB Output is correct
59 Correct 1646 ms 124756 KB Output is correct
60 Correct 1816 ms 124204 KB Output is correct
61 Correct 1748 ms 124848 KB Output is correct
62 Correct 1741 ms 124476 KB Output is correct
63 Correct 1607 ms 124772 KB Output is correct
64 Correct 1069 ms 124580 KB Output is correct
65 Correct 1294 ms 124544 KB Output is correct
66 Correct 878 ms 112516 KB Output is correct
67 Correct 1002 ms 116020 KB Output is correct
68 Correct 1188 ms 120368 KB Output is correct
69 Correct 1078 ms 118192 KB Output is correct
70 Correct 1519 ms 127452 KB Output is correct
71 Correct 1563 ms 127660 KB Output is correct
72 Correct 1623 ms 127544 KB Output is correct
73 Correct 1609 ms 127684 KB Output is correct
74 Correct 1631 ms 121200 KB Output is correct
75 Correct 1552 ms 126884 KB Output is correct
76 Correct 1561 ms 123104 KB Output is correct
77 Correct 1431 ms 121312 KB Output is correct
78 Correct 1451 ms 121552 KB Output is correct
79 Correct 1612 ms 127708 KB Output is correct
80 Correct 1421 ms 121204 KB Output is correct
81 Correct 1574 ms 127320 KB Output is correct
82 Correct 1498 ms 121444 KB Output is correct
83 Correct 1735 ms 127908 KB Output is correct
84 Correct 1428 ms 121576 KB Output is correct
85 Correct 1644 ms 127952 KB Output is correct
86 Correct 1410 ms 121848 KB Output is correct
87 Correct 1760 ms 128164 KB Output is correct
88 Correct 1463 ms 121588 KB Output is correct
89 Correct 1299 ms 128076 KB Output is correct