zoukankan      html  css  js  c++  java
  • cf1088C Ehab and a 2-operation task (构造)

    题意:给一个数列,你可以进行至多n+1次操作,每次给一个前缀对某数取模或者加某数,使得最后数列严格单增

    考虑到因为是前缀和而且还不能加负数,光靠加是不能让前面的小于后面的

    所以要让他先在模某数意义下单增,最后再模一下

    先钦定好mod,然后从后往前做,这时候a[i]已经定下来,只要给前i个加上某数使得(a[i-1]-a[i])%mod=-1即可

    一共加了N次,最后还要模一次

     1 #include<bits/stdc++.h>
     2 #define pa pair<int,int>
     3 #define CLR(a,x) memset(a,x,sizeof(a))
     4 #define MP make_pair
     5 using namespace std;
     6 typedef long long ll;
     7 const int maxn=1e5+10;
     8 
     9 inline char gc(){
    10     return getchar();
    11     static const int maxs=1<<16;static char buf[maxs],*p1=buf,*p2=buf;
    12     return p1==p2&&(p2=(p1=buf)+fread(buf,1,maxs,stdin),p1==p2)?EOF:*p1++;
    13 }
    14 inline int rd(){
    15     int x=0;char c=gc();bool neg=0;
    16     while(c<'0'||c>'9'){if(c=='-') neg=1;c=gc();}
    17     while(c>='0'&&c<='9') x=(x<<1)+(x<<3)+c-'0',c=gc();
    18     return neg?(~x+1):x;
    19 }
    20 
    21 int N;
    22 ll a[maxn];
    23 
    24 int main(){
    25     //freopen("","r",stdin);
    26     int i,j,k;
    27     N=rd();
    28     for(i=1;i<=N;i++) a[i]=rd();
    29     int mod=2001;
    30     ll inc=0;
    31     printf("%d
    ",N+1);
    32     a[N+1]=2000;
    33     for(i=N;i;i--){
    34         a[i]+=inc;
    35         int d=((a[i+1]-1-a[i])%mod+mod)%mod;
    36         inc+=d;a[i]+=d;
    37         printf("1 %d %d
    ",i,d);
    38     }
    39     printf("2 %d %d
    ",N,mod);
    40     return 0;
    41 }
  • 相关阅读:
    百度高级搜索技巧
    JRebel插件使用详解
    css3自适应布局单位vw,vh详解
    vue的MVVM原理
    JS实现全屏和退出全屏
    设置不定宽高的元素垂直水平居中
    微信小程序启动更新机制
    了解MVVM原理
    xss攻击和csrf攻击的定义及区别
    跨站脚本漏洞(XSS)基础讲解
  • 原文地址:https://www.cnblogs.com/Ressed/p/10088989.html
Copyright © 2011-2022 走看看