Submission #956478

# Submission time Handle Problem Language Result Execution time Memory
956478 2024-04-02T05:22:49 Z modwwe Garaža (COCI17_garaza) C++17
0 / 160
15 ms 29788 KB
#pragma GCC optimize("O3")
#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#define int long long
#define down cout<<'\n';
#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".ans","w",stdout)
#define pb push_back
#define checktime   cerr << (double)clock() / CLOCKS_PER_SEC * 1000  << " ms";

using namespace std;
void phongbeo();
mt19937 rd(chrono::high_resolution_clock::now().time_since_epoch().count    ());
const int mod2=1e9+7;
const int  mod1=998244353;
struct ib
{
    int a;
    int b;
};
struct icd
{
    int a,b;
};
struct ic
{
    int a,b,c;
};
struct id
{
    int a,b,c,d;
};
int n,m,s2,s4,s3,sf,k,r,dem=0,mid,s5,s6,mx,s7,s8,s9,mx2,res,dem2=0,l;
int  s,i,s10,s12;
int el=29;
main()
{
#ifndef ONLINE_JUDGE
fin(task),fou(task);
#endif
    NHP
//modwwe
    phongbeo(),down
    //checktime
}
int t[400001];
int t2[400001];
int sz[400001];
int lazy[400001];
int t3[400001];
int a[100001];

void update(int node,int l,int r,int l1,int r1,int v)
{
    if(l>r1||r<l1) return;
    if(l>=l1&&r<=r1)
    {
        t[node]=v;
        return;
    }
    int mid=l+r>>1;
    update(node<<1,l,mid,l1,r1,v);
    update(node<<1|1,mid+1,r,l1,r1,v);
    t[node]=__gcd(t[node<<1],t[node<<1|1]);
}
int get(int node,int l,int r,int l1,int r1)
{
    if(l>r1||r<l1) return 0;
    if(l>=l1&&r<=r1) return t[node];
    int mid=l+r>>1;
    return __gcd(get(node<<1,l,mid,l1,r1),get(node<<1|1,mid+1,r,l1,r1));
}
void ff(int x)
{
    for(int i=x*2; i<=x*2+1; i++)
    {
        t3[i]=lazy[x];
        t2[i]=sz[i]*lazy[x];
        lazy[i]=lazy[x];
    }
    lazy[x]=0;
}
void upd2(int node,int l,int r,int l1,int r1,int v)
{
    if(l>r1||r<l1) return;
    if(l>=l1&&r<=r1)
    {
        t2[node]=sz[node]*v;
        t3[node]=v;
        lazy[node]=v;
        return;
    }
    if(lazy[node]!=0)
        ff(node);
    int mid=l+r>>1;
    upd2(node<<1,l,mid,l1,r1,v);
    upd2(node<<1|1,mid+1,r,l1,r1,v);
    t2[node]=t2[node<<1]+t2[node<<1|1];
    t3[node]=min(t3[node<<1],t3[node<<1|1]);
//if(l1==2&&r1==2) cout<<t2[node]<<" "<<l<<" "<<r,down
}
int get2(int node,int l,int r,int l1,int r1)
{ if(l1>r1) return 0;
    if(l>r1||r<l1) return 0;
    if(l>=l1&&r<=r1) return t2[node];
    if(lazy[node]!=0)
        ff(node);
    int mid=l+r>>1;
    return get2(node<<1,l,mid,l1,r1)+get2(node<<1|1,mid+1,r,l1,r1);
}
void build(int node,int l,int r)
{t2[node]=0;
lazy[node]=0;
t3[node]=0;
    sz[node]=r-l+1;
    if(l==r)
    {
        t[node]=a[l];
        return;
    }
    int mid=l+r>>1;
    build(node<<1,l,mid);
    build(node<<1|1,mid+1,r);
    t[node]=__gcd(t[node<<1],t[node<<1|1]);
}
int get3(int node,int l,int r,int l1,int r1)
{
    if(l>r1||r<l1)return n+1;
    if(l>=l1&&r<=r1) return t3[node];
    if(lazy[node]!=0)
        ff(node);
    int mid=l+r>>1;
    return min(get3(node<<1,l,mid,l1,r1),get3(node<<1|1,mid+1,r,l1,r1));
}
void phongbeo()
{
    cin>>n>>m;
    for(int i=1; i<=n; i++)
        cin>>a[i];
    build(1,1,n);
    l=1;
    for(int i=1; i<=n; i++)
    {
        while(get(1,1,n,i,l)!=1&&l<=n)
            l++;
        upd2(1,1,n,i,i,l-1);
    }
    for(int i=1; i<=m; i++)
    {
        cin>>l;
        if(l==1)
        {
            cin>>l>>r;
            s7=l;
            a[l]=r;
            l=1;
            r=s7-1;
            while(l<=r)
            {
                int mid=l+r>>1;
                if(get(1,1,n,mid,s7-1)==1)l=mid+1;
                else r=mid-1;
            }
if(l<=s7-1)
            upd2(1,1,n,l,s7-1,s7-1);
            update(1,1,n,s7,s7,a[s7]);
           if(a[s7]==1) upd2(1,1,n,s7,s7,s7-1);
            else upd2(1,1,n,s7,s7,s7);

            vector<ib> v;
            vector<ib> v2;
            s2=a[s7];
            s3=s7;
            while(s2!=1&&s3>=0)
            { dem++;
                l=1;
                r=s3;
                while(l<=r)
                {
                    int mid=l+r>>1;
                    s4=get(1,1,n,mid,s7);
                    if(s4!=s2)l=mid+1;
                    else r=mid-1;
                }
                v.pb({s2,l});
                s2=__gcd(s2,a[l-1]);
                s3=l-2;
            }
            s2=a[s7];
            s3=s7;
            while(s2!=1&&s3<=n+1)
            {
                l=s3;
                r=n;
                while(l<=r)
                {
                    int mid=l+r>>1;
                    s4=get(1,1,n,s7,mid);
                    if(s4!=s2)r=mid-1;
                    else l=mid+1;
                }
                v2.pb({s2,r});
                s2=__gcd(s2,a[r+1]);
                s3=r+2;
            }
            l=0;
            s2=s7;
            reverse(v2.begin(),v2.end());
            for(auto x:v)
            {
                while(__gcd(x.a,v2[l].a)==1&&l<v2.size())
                    l++;
                if(__gcd(x.a,v2[l].a)!=1)
                {
                    upd2(1,1,n,x.b,s2,v2[l].b);
                    s2=x.b-1;
                }
                else break;
            }
        }
        else if(l==2)
        {
            cin>>s2>>s3;
            l=s2;
            r=s3;
            while(l<=r)
            {
                int mid=l+r>>1;
                if(get3(1,1,n,mid,s3)>s3)r=mid-1;
                else l=mid+1;
            }
            cout<<(s3-r)*(s3)+get2(1,1,n,s2,r)-(s3+s2)*(s3-s2+1)/2+(s3-s2+1),down
        }
    }
}
/*
5 7
3 5 2 4 3
1 2 6
1 1 6
1 2 4
1 3 3
1 3 4
1 4 6
2 1 5

*/

Compilation message

garaza.cpp:41:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   41 | main()
      | ^~~~
garaza.cpp: In function 'void update(long long int, long long int, long long int, long long int, long long int, long long int)':
garaza.cpp:66:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   66 |     int mid=l+r>>1;
      |             ~^~
garaza.cpp: In function 'long long int get(long long int, long long int, long long int, long long int, long long int)':
garaza.cpp:75:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   75 |     int mid=l+r>>1;
      |             ~^~
garaza.cpp: In function 'void upd2(long long int, long long int, long long int, long long int, long long int, long long int)':
garaza.cpp:100:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  100 |     int mid=l+r>>1;
      |             ~^~
garaza.cpp: In function 'long long int get2(long long int, long long int, long long int, long long int, long long int)':
garaza.cpp:113:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  113 |     int mid=l+r>>1;
      |             ~^~
garaza.cpp: In function 'void build(long long int, long long int, long long int)':
garaza.cpp:126:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  126 |     int mid=l+r>>1;
      |             ~^~
garaza.cpp: In function 'long long int get3(long long int, long long int, long long int, long long int, long long int)':
garaza.cpp:137:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  137 |     int mid=l+r>>1;
      |             ~^~
garaza.cpp: In function 'void phongbeo()':
garaza.cpp:165:26: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  165 |                 int mid=l+r>>1;
      |                         ~^~
garaza.cpp:169:1: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
  169 | if(l<=s7-1)
      | ^~
garaza.cpp:171:13: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
  171 |             update(1,1,n,s7,s7,a[s7]);
      |             ^~~~~~
garaza.cpp:185:30: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  185 |                     int mid=l+r>>1;
      |                             ~^~
garaza.cpp:202:30: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  202 |                     int mid=l+r>>1;
      |                             ~^~
garaza.cpp:216:47: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<ib>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  216 |                 while(__gcd(x.a,v2[l].a)==1&&l<v2.size())
      |                                              ~^~~~~~~~~~
garaza.cpp:233:26: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  233 |                 int mid=l+r>>1;
      |                         ~^~
garaza.cpp: In function 'int main()':
garaza.cpp:11:23: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 | #define fin(x) freopen(x".inp","r",stdin)
      |                ~~~~~~~^~~~~~~~~~~~~~~~~~~
garaza.cpp:44:1: note: in expansion of macro 'fin'
   44 | fin(task),fou(task);
      | ^~~
garaza.cpp:12:23: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 | #define fou(x) freopen(x".ans","w",stdout)
      |                ~~~~~~~^~~~~~~~~~~~~~~~~~~~
garaza.cpp:44:11: note: in expansion of macro 'fou'
   44 | fin(task),fou(task);
      |           ^~~
# Verdict Execution time Memory Grader output
1 Runtime error 15 ms 29788 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 15 ms 29788 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 14 ms 29788 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 14 ms 29788 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -