답안 #1017434

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1017434 2024-07-09T07:56:42 Z modwwe Fish 2 (JOI22_fish2) C++17
100 / 100
1064 ms 408256 KB
//https://www.instagram.com/_modwwe/
#pragma GCC optimize("Ofast,unroll-loops")
//#pragma GCC target("avx2,bmi,bmi2")
#include<bits/stdc++.h>
#define int long long
//#define ll long long
#define down cout<<'\n';
#define debug cout<<"cuuuuuuuu",down
#define NHP     ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);
#define modwwe  int t;cin>>t; while(t--)
#define bit(i,j) (i>>j&1)
#define sobit(a) __builtin_popcountll(a)
#define task "test"
#define fin(x) freopen(x".inp","r",stdin)
#define fou(x) freopen(x".out","w",stdout)
#define pb push_back
#define checktime   cerr << (double)clock() / CLOCKS_PER_SEC * 1000  << " ms";
using namespace std;
void phongbeo();
const int inf=1e18;
const int mod2=1e9+7;
const int  mod1=998244353;
struct icd
{
    int a,b;
};
struct ib
{
    int a;
    int b;
};
struct ic
{
    int a,b,c;
};
struct id
{
    int a,b,c,d;
};
struct ie
{
    int a,b,c, d,e,f;

};
int n,m,s1,s2,s4,s3,sf,k,r,mid,s5,s6,mx,s7,s8,s9,mx2,res,dem2=0,dem=0,l;
int  i,s10,s12;
int el=29;
int sa,sb;
main()
{
#ifndef ONLINE_JUDGE
    //    fin(task),fou(task);
#endif
    NHP
    /// cin>>s1;
    // modwwe
    phongbeo(),down
}
struct IT
{
    int sl,sr;/// size left
    /// size right
    ic cr[32];
    ic cl[32];
    int c,d;
    int a;
} t[400001],ans;
int a[100001];
vector<id> v;
bool cmp(id a,id b)
{
    return a.a<b.a;
}
IT mer(int y,int z,int mid,int l,int r)
{
    IT tx;
    v.clear();
    for(int i=0; i<=t[z].sl; i++)
        v.pb({a[t[z].cl[i].b]-t[z].cl[i].a,t[z].cl[i].a,t[z].cl[i].b,i});
    sort(v.begin(),v.end(),cmp);
    s4=-1 ;
    mx=t[y].sr+1;
    s5=-1;
    s6=-1;
    for(auto x:v )
    {
        while(mx>0&&t[y].cr[mx-1].a<x.a)s5=max(s5,a[t[y].cr[mx-1].b]-t[y].cr[mx-1].a),mx--;
        if(s5>x.b)
        {
            s4=max(s4,x.c);
            if(s4==x.c)
                s6=x.d;
        }
    }
    tx.d=t[z].d;
    s9=t[z].d;
    if(s4!=-1) tx.d+=s4-mid-t[z].cl[s6].c-1,s9+=s4-mid-t[z].cl[s6].c-1;
    s10=s4;
    v.clear() ;
    for(int i=0; i<=t[y].sr; i++)
        v.pb({a[t[y].cr[i].b]-t[y].cr[i].a,t[y].cr[i].a,t[y].cr[i].b,i});
    sort(v.begin(),v.end(),cmp);
    s4=n+1;
    mx=-1;
    s5=-1;
    s6=0;
    for(auto x:v)
    {
        while(mx<t[z].sl&&t[z].cl[mx+1].a<x.a)
            mx++,s5=max(s5,a[t[z].cl[mx].b]-t[z].cl[mx].a);
        if(s5>x.b)
        {
            s4=min(s4,x.c);
            if(s4==x.c) s6=x.d;
        }
    }
    s8=t[y].d;
    tx.d+=t[y].d;
    if(s4!=n+1)tx.d+=mid-s4-t[y].cr[s6].c,s8+=mid-s4-t[y].cr[s6].c;
    bool dl=0;
    bool dr=0;
    dem=-1;
    for(int i=0; i<=t[y].sl; i++)
        tx.cl[++dem]=t[y].cl[i];
    sa=-1;
    for(int i=0; i<=t[z].sl; i++)
        if(t[z].cl[i].a+t[y].a<a[t[z].cl[i].b])
        {
            tx.cl[++dem]=t[z].cl[i],
                         dl=1;
            if(s10!=-1)
            {
                if(t[z].cl[i].b<s10)
                {
                    tx.cl[dem].c=t[z].cl[i].b-mid;
                }
                else tx.cl[dem].c+=s9-t[z].d;
            }
            tx.cl[dem].c+=s8;
            tx.cl[dem].a+=t[y].a;
        }
    sa=dem;
//if(l==1&&r==3)cout<<t[y].d,down
    tx.sl=dem;
    dem=-1;
    sb=n+1;
    for(int i=0; i<=t[y].sr; i++)
        if(t[y].cr[i].a+t[z].a<a[t[y].cr[i].b])
        {
            tx.cr[++dem]=t[y].cr[i],
                         tx.cr[dem].a+=t[z].a,
                                       dr=1;
            if(s4!=n+1)
            {
                if(s4<t[y].cr[i].b)tx.cr[dem].c=mid-t[y].cr[i].b+1;
                else tx.cr[dem].c+=s8-t[y].d;
            }
            tx.cr[dem].c+=s9;
        }
    for(int i=0; i<=t[z].sr; i++)
        tx.cr[++dem]=t[z].cr[i];
    sb=0;
    tx.c=s9-tx.cl[sa].c+tx.cl[sa].b-l;
    tx.c+=s8-tx.cr[sb].c+r-tx.cr[sb].b;
    tx.a=t[y].a+t[z].a;
    tx.sr=dem;
    return tx;
}
void build(int node,int l,int r)
{
    if(l==r)
    {
        t[node].cr[0]=t[node].cl[0]= {0,l};
        t[node].a=a[l];
        return;
    }
    int mid=l+r>>1;
    build(node<<1,l,mid);
    build(node<<1|1,mid+1,r);
    t[node]=mer(node<<1,node<<1|1,mid,l,r);
}
void upd(int node,int l,int r,int l1)
{
    if(l==r)
    {
        t[node].cr[0]=t[node].cl[0]= {0,l};
        t[node].a=a[l];
        return;
    }
    int mid=l+r>>1;
    if(l1<=mid) upd(node<<1,l,mid,l1);
    else upd(node<<1|1,mid+1,r,l1);
    t[node]=mer(node<<1,node<<1|1,mid,l,r);

}
void get(int node,int l,int r, int l1,int r1)
{
    if(l>r1||r<l1) return ;
    if(l>=l1&&r<=r1)
    {
        if(l==l1) t[0]=t[node];
        else t[0]=mer(0,node,l-1,l1,r);
        return;
    }
    int mid=l+r>>1;
    get(node<<1,l,mid,l1,r1);
    get(node<<1|1,mid+1,r,l1,r1);
}
void phongbeo()
{
    cin>>n;
    for(int i=1; i<=n; i++)
        cin>>a[i];
    build(1,1,n);
    cin>>m;
    for(int i=1; i<=m; i++)
    {
        cin>>l;
        if(l==1)
        {
            cin>>l>>r;
            a[l]=r;
            upd(1,1,n,l);
        }
        else
        {
            t[0].sl=-1;
            t[0].sr=-1;
            cin>>l>>r;
            get(1,1,n,l,r);
            cout<<r-l+1-t[0].c,down
        }
    }

}

Compilation message

fish2.cpp:49:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   49 | main()
      | ^~~~
fish2.cpp: In function 'IT mer(long long int, long long int, long long int, long long int, long long int)':
fish2.cpp:120:10: warning: variable 'dl' set but not used [-Wunused-but-set-variable]
  120 |     bool dl=0;
      |          ^~
fish2.cpp:121:10: warning: variable 'dr' set but not used [-Wunused-but-set-variable]
  121 |     bool dr=0;
      |          ^~
fish2.cpp: In function 'void build(long long int, long long int, long long int)':
fish2.cpp:177:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  177 |     int mid=l+r>>1;
      |             ~^~
fish2.cpp: In function 'void upd(long long int, long long int, long long int, long long int)':
fish2.cpp:190:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  190 |     int mid=l+r>>1;
      |             ~^~
fish2.cpp: In function 'void get(long long int, long long int, long long int, long long int, long long int)':
fish2.cpp:205:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  205 |     int mid=l+r>>1;
      |             ~^~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 2 ms 2076 KB Output is correct
6 Correct 2 ms 2004 KB Output is correct
7 Correct 2 ms 1884 KB Output is correct
8 Correct 2 ms 1884 KB Output is correct
9 Correct 2 ms 1884 KB Output is correct
10 Correct 2 ms 1884 KB Output is correct
11 Correct 1 ms 1884 KB Output is correct
12 Correct 3 ms 2140 KB Output is correct
13 Correct 2 ms 1884 KB Output is correct
14 Correct 3 ms 1860 KB Output is correct
15 Correct 2 ms 1884 KB Output is correct
16 Correct 2 ms 1884 KB Output is correct
17 Correct 2 ms 1884 KB Output is correct
18 Correct 2 ms 1884 KB Output is correct
19 Correct 2 ms 1884 KB Output is correct
20 Correct 2 ms 1884 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 155 ms 405972 KB Output is correct
3 Correct 154 ms 405840 KB Output is correct
4 Correct 150 ms 406032 KB Output is correct
5 Correct 152 ms 405840 KB Output is correct
6 Correct 155 ms 406352 KB Output is correct
7 Correct 152 ms 405588 KB Output is correct
8 Correct 148 ms 406356 KB Output is correct
9 Correct 178 ms 405636 KB Output is correct
10 Correct 155 ms 405840 KB Output is correct
11 Correct 155 ms 405620 KB Output is correct
12 Correct 151 ms 405588 KB Output is correct
13 Correct 149 ms 405612 KB Output is correct
14 Correct 153 ms 405964 KB Output is correct
15 Correct 158 ms 406040 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 2 ms 2076 KB Output is correct
6 Correct 2 ms 2004 KB Output is correct
7 Correct 2 ms 1884 KB Output is correct
8 Correct 2 ms 1884 KB Output is correct
9 Correct 2 ms 1884 KB Output is correct
10 Correct 2 ms 1884 KB Output is correct
11 Correct 1 ms 1884 KB Output is correct
12 Correct 3 ms 2140 KB Output is correct
13 Correct 2 ms 1884 KB Output is correct
14 Correct 3 ms 1860 KB Output is correct
15 Correct 2 ms 1884 KB Output is correct
16 Correct 2 ms 1884 KB Output is correct
17 Correct 2 ms 1884 KB Output is correct
18 Correct 2 ms 1884 KB Output is correct
19 Correct 2 ms 1884 KB Output is correct
20 Correct 2 ms 1884 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 155 ms 405972 KB Output is correct
23 Correct 154 ms 405840 KB Output is correct
24 Correct 150 ms 406032 KB Output is correct
25 Correct 152 ms 405840 KB Output is correct
26 Correct 155 ms 406352 KB Output is correct
27 Correct 152 ms 405588 KB Output is correct
28 Correct 148 ms 406356 KB Output is correct
29 Correct 178 ms 405636 KB Output is correct
30 Correct 155 ms 405840 KB Output is correct
31 Correct 155 ms 405620 KB Output is correct
32 Correct 151 ms 405588 KB Output is correct
33 Correct 149 ms 405612 KB Output is correct
34 Correct 153 ms 405964 KB Output is correct
35 Correct 158 ms 406040 KB Output is correct
36 Correct 163 ms 406100 KB Output is correct
37 Correct 158 ms 405844 KB Output is correct
38 Correct 161 ms 405844 KB Output is correct
39 Correct 160 ms 406100 KB Output is correct
40 Correct 185 ms 405864 KB Output is correct
41 Correct 166 ms 406628 KB Output is correct
42 Correct 159 ms 406340 KB Output is correct
43 Correct 180 ms 405584 KB Output is correct
44 Correct 163 ms 405696 KB Output is correct
45 Correct 163 ms 405844 KB Output is correct
46 Correct 163 ms 406096 KB Output is correct
47 Correct 161 ms 405584 KB Output is correct
48 Correct 162 ms 405588 KB Output is correct
49 Correct 158 ms 405668 KB Output is correct
50 Correct 163 ms 406352 KB Output is correct
51 Correct 158 ms 406100 KB Output is correct
52 Correct 155 ms 406096 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 155 ms 405972 KB Output is correct
3 Correct 154 ms 405840 KB Output is correct
4 Correct 150 ms 406032 KB Output is correct
5 Correct 152 ms 405840 KB Output is correct
6 Correct 155 ms 406352 KB Output is correct
7 Correct 152 ms 405588 KB Output is correct
8 Correct 148 ms 406356 KB Output is correct
9 Correct 178 ms 405636 KB Output is correct
10 Correct 155 ms 405840 KB Output is correct
11 Correct 155 ms 405620 KB Output is correct
12 Correct 151 ms 405588 KB Output is correct
13 Correct 149 ms 405612 KB Output is correct
14 Correct 153 ms 405964 KB Output is correct
15 Correct 158 ms 406040 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 855 ms 407616 KB Output is correct
18 Correct 673 ms 407868 KB Output is correct
19 Correct 851 ms 407424 KB Output is correct
20 Correct 787 ms 407304 KB Output is correct
21 Correct 834 ms 407508 KB Output is correct
22 Correct 645 ms 407892 KB Output is correct
23 Correct 851 ms 407544 KB Output is correct
24 Correct 804 ms 407632 KB Output is correct
25 Correct 858 ms 407312 KB Output is correct
26 Correct 850 ms 407384 KB Output is correct
27 Correct 502 ms 408252 KB Output is correct
28 Correct 461 ms 408144 KB Output is correct
29 Correct 469 ms 408256 KB Output is correct
30 Correct 583 ms 407120 KB Output is correct
31 Correct 549 ms 407120 KB Output is correct
32 Correct 847 ms 407340 KB Output is correct
33 Correct 902 ms 407904 KB Output is correct
34 Correct 867 ms 407404 KB Output is correct
35 Correct 919 ms 407380 KB Output is correct
36 Correct 1064 ms 407812 KB Output is correct
37 Correct 451 ms 407124 KB Output is correct
38 Correct 420 ms 407120 KB Output is correct
39 Correct 491 ms 407888 KB Output is correct
40 Correct 516 ms 407892 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 155 ms 405972 KB Output is correct
3 Correct 154 ms 405840 KB Output is correct
4 Correct 150 ms 406032 KB Output is correct
5 Correct 152 ms 405840 KB Output is correct
6 Correct 155 ms 406352 KB Output is correct
7 Correct 152 ms 405588 KB Output is correct
8 Correct 148 ms 406356 KB Output is correct
9 Correct 178 ms 405636 KB Output is correct
10 Correct 155 ms 405840 KB Output is correct
11 Correct 155 ms 405620 KB Output is correct
12 Correct 151 ms 405588 KB Output is correct
13 Correct 149 ms 405612 KB Output is correct
14 Correct 153 ms 405964 KB Output is correct
15 Correct 158 ms 406040 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 672 ms 406916 KB Output is correct
18 Correct 613 ms 407376 KB Output is correct
19 Correct 542 ms 406864 KB Output is correct
20 Correct 485 ms 407372 KB Output is correct
21 Correct 713 ms 407120 KB Output is correct
22 Correct 610 ms 407392 KB Output is correct
23 Correct 760 ms 406764 KB Output is correct
24 Correct 567 ms 407304 KB Output is correct
25 Correct 649 ms 406864 KB Output is correct
26 Correct 432 ms 408000 KB Output is correct
27 Correct 533 ms 408144 KB Output is correct
28 Correct 471 ms 407508 KB Output is correct
29 Correct 457 ms 408148 KB Output is correct
30 Correct 563 ms 408072 KB Output is correct
31 Correct 544 ms 407360 KB Output is correct
32 Correct 630 ms 407376 KB Output is correct
33 Correct 707 ms 406884 KB Output is correct
34 Correct 567 ms 407672 KB Output is correct
35 Correct 615 ms 407416 KB Output is correct
36 Correct 531 ms 407380 KB Output is correct
37 Correct 502 ms 407096 KB Output is correct
38 Correct 374 ms 407120 KB Output is correct
39 Correct 425 ms 407636 KB Output is correct
40 Correct 275 ms 407892 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 2 ms 2076 KB Output is correct
6 Correct 2 ms 2004 KB Output is correct
7 Correct 2 ms 1884 KB Output is correct
8 Correct 2 ms 1884 KB Output is correct
9 Correct 2 ms 1884 KB Output is correct
10 Correct 2 ms 1884 KB Output is correct
11 Correct 1 ms 1884 KB Output is correct
12 Correct 3 ms 2140 KB Output is correct
13 Correct 2 ms 1884 KB Output is correct
14 Correct 3 ms 1860 KB Output is correct
15 Correct 2 ms 1884 KB Output is correct
16 Correct 2 ms 1884 KB Output is correct
17 Correct 2 ms 1884 KB Output is correct
18 Correct 2 ms 1884 KB Output is correct
19 Correct 2 ms 1884 KB Output is correct
20 Correct 2 ms 1884 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 155 ms 405972 KB Output is correct
23 Correct 154 ms 405840 KB Output is correct
24 Correct 150 ms 406032 KB Output is correct
25 Correct 152 ms 405840 KB Output is correct
26 Correct 155 ms 406352 KB Output is correct
27 Correct 152 ms 405588 KB Output is correct
28 Correct 148 ms 406356 KB Output is correct
29 Correct 178 ms 405636 KB Output is correct
30 Correct 155 ms 405840 KB Output is correct
31 Correct 155 ms 405620 KB Output is correct
32 Correct 151 ms 405588 KB Output is correct
33 Correct 149 ms 405612 KB Output is correct
34 Correct 153 ms 405964 KB Output is correct
35 Correct 158 ms 406040 KB Output is correct
36 Correct 163 ms 406100 KB Output is correct
37 Correct 158 ms 405844 KB Output is correct
38 Correct 161 ms 405844 KB Output is correct
39 Correct 160 ms 406100 KB Output is correct
40 Correct 185 ms 405864 KB Output is correct
41 Correct 166 ms 406628 KB Output is correct
42 Correct 159 ms 406340 KB Output is correct
43 Correct 180 ms 405584 KB Output is correct
44 Correct 163 ms 405696 KB Output is correct
45 Correct 163 ms 405844 KB Output is correct
46 Correct 163 ms 406096 KB Output is correct
47 Correct 161 ms 405584 KB Output is correct
48 Correct 162 ms 405588 KB Output is correct
49 Correct 158 ms 405668 KB Output is correct
50 Correct 163 ms 406352 KB Output is correct
51 Correct 158 ms 406100 KB Output is correct
52 Correct 155 ms 406096 KB Output is correct
53 Correct 0 ms 348 KB Output is correct
54 Correct 855 ms 407616 KB Output is correct
55 Correct 673 ms 407868 KB Output is correct
56 Correct 851 ms 407424 KB Output is correct
57 Correct 787 ms 407304 KB Output is correct
58 Correct 834 ms 407508 KB Output is correct
59 Correct 645 ms 407892 KB Output is correct
60 Correct 851 ms 407544 KB Output is correct
61 Correct 804 ms 407632 KB Output is correct
62 Correct 858 ms 407312 KB Output is correct
63 Correct 850 ms 407384 KB Output is correct
64 Correct 502 ms 408252 KB Output is correct
65 Correct 461 ms 408144 KB Output is correct
66 Correct 469 ms 408256 KB Output is correct
67 Correct 583 ms 407120 KB Output is correct
68 Correct 549 ms 407120 KB Output is correct
69 Correct 847 ms 407340 KB Output is correct
70 Correct 902 ms 407904 KB Output is correct
71 Correct 867 ms 407404 KB Output is correct
72 Correct 919 ms 407380 KB Output is correct
73 Correct 1064 ms 407812 KB Output is correct
74 Correct 451 ms 407124 KB Output is correct
75 Correct 420 ms 407120 KB Output is correct
76 Correct 491 ms 407888 KB Output is correct
77 Correct 516 ms 407892 KB Output is correct
78 Correct 0 ms 348 KB Output is correct
79 Correct 672 ms 406916 KB Output is correct
80 Correct 613 ms 407376 KB Output is correct
81 Correct 542 ms 406864 KB Output is correct
82 Correct 485 ms 407372 KB Output is correct
83 Correct 713 ms 407120 KB Output is correct
84 Correct 610 ms 407392 KB Output is correct
85 Correct 760 ms 406764 KB Output is correct
86 Correct 567 ms 407304 KB Output is correct
87 Correct 649 ms 406864 KB Output is correct
88 Correct 432 ms 408000 KB Output is correct
89 Correct 533 ms 408144 KB Output is correct
90 Correct 471 ms 407508 KB Output is correct
91 Correct 457 ms 408148 KB Output is correct
92 Correct 563 ms 408072 KB Output is correct
93 Correct 544 ms 407360 KB Output is correct
94 Correct 630 ms 407376 KB Output is correct
95 Correct 707 ms 406884 KB Output is correct
96 Correct 567 ms 407672 KB Output is correct
97 Correct 615 ms 407416 KB Output is correct
98 Correct 531 ms 407380 KB Output is correct
99 Correct 502 ms 407096 KB Output is correct
100 Correct 374 ms 407120 KB Output is correct
101 Correct 425 ms 407636 KB Output is correct
102 Correct 275 ms 407892 KB Output is correct
103 Correct 819 ms 406724 KB Output is correct
104 Correct 627 ms 407636 KB Output is correct
105 Correct 891 ms 407512 KB Output is correct
106 Correct 721 ms 407380 KB Output is correct
107 Correct 864 ms 406868 KB Output is correct
108 Correct 655 ms 407636 KB Output is correct
109 Correct 855 ms 407236 KB Output is correct
110 Correct 670 ms 407456 KB Output is correct
111 Correct 907 ms 407340 KB Output is correct
112 Correct 687 ms 407540 KB Output is correct
113 Correct 574 ms 408148 KB Output is correct
114 Correct 506 ms 408228 KB Output is correct
115 Correct 618 ms 407336 KB Output is correct
116 Correct 609 ms 407444 KB Output is correct
117 Correct 517 ms 408144 KB Output is correct
118 Correct 584 ms 407264 KB Output is correct
119 Correct 541 ms 408144 KB Output is correct
120 Correct 611 ms 407376 KB Output is correct
121 Correct 579 ms 407376 KB Output is correct
122 Correct 651 ms 407532 KB Output is correct
123 Correct 879 ms 407020 KB Output is correct
124 Correct 662 ms 407420 KB Output is correct
125 Correct 845 ms 407332 KB Output is correct
126 Correct 737 ms 407364 KB Output is correct
127 Correct 614 ms 407124 KB Output is correct
128 Correct 485 ms 407632 KB Output is correct
129 Correct 564 ms 407708 KB Output is correct
130 Correct 528 ms 407888 KB Output is correct