标签:图片 const ios 数位 .com ide eve 斐波那契 def
https://codeforces.com/contest/719
AC代码
#include<bits/stdc++.h> using namespace std; typedef long long ll; # define IOS ios::sync_with_stdio(false); cin.tie(0);cout.tie(0) //struct note{ // int x ,y; //}st[300000 + 10]; //set<ll> s1,s2; //ll a[300000 + 10][2]; int a[100]; int main(){ IOS; int n; cin >> n; for(int i = 1; i<= n ; i++){ cin >> a[i]; } if(n==1 && a[1] == 15){puts("DOWN"); return 0;} if(n==1 && a[1] == 0){puts("UP"); return 0;} if(n == 1) { puts("-1"); return 0; } if(a[n] == 15 && a[n] > a[n-1]) { puts("DOWN"); return 0; } if(a[n] == 0 && a[n-1] == 1) { puts("UP"); return 0 ; } if(a[n] > a[n-1]) puts("UP"); else puts("DOWN"); return 0; }
AC代码
#include<bits/stdc++.h> using namespace std; typedef long long ll; # define IOS ios::sync_with_stdio(false); cin.tie(0);cout.tie(0) //struct note{ // int x ,y; //}st[300000 + 10]; //set<ll> s1,s2; //ll a[300000 + 10][2]; string a; int main(){ IOS; int n; cin >> n; cin >> a; int x = 0 , y = 0; for(int i = 0 ; i < a.size();i++){ if(i % 2 == 0){ if(a[i]!=‘r‘) x ++; } else { if(a[i] != ‘b‘) y++; } } int ans = 0; ans = abs(x - y) + min(x,y); x = y = 0; for(int i = 0 ; i < a.size();i++){ if(i % 2 != 0){ if(a[i]!=‘r‘) x ++; } else { if(a[i] != ‘b‘) y++; } } ans = min(ans , abs(x - y) + min(x,y)); cout << ans << endl; return 0; }
AC代码
#include<bits/stdc++.h> using namespace std; typedef long long ll; # define IOS ios::sync_with_stdio(false); cin.tie(0);cout.tie(0) //struct note{ // ll x ,y; //}st[300000 + 10]; //set<ll> s1,s2; //ll a[300000 + 10][2]; string s; int main() { int n,t; scanf("%d%d",&n,&t); cin>>s; int i=0; while(s[i]!=‘.‘)i++; while(i<n&&s[i]<‘5‘)i++; if(i==n) { cout<<s<<endl; return 0; } i--;int len=0; while(t>0) { if(s[i]!=‘.‘)s[i]++; else{ i--;len=i; while(i>=0&&s[i]==‘9‘)s[i--]=‘0‘; if(i==-1)cout<<‘1‘; else s[i]++; break; } if(s[i]<‘5‘) { len=i; break; } else { len=i; i--; } t--; } for(int k=0;k<=len;k++) cout<<s[k]; cout<<endl; }
AC代码
#include <algorithm> #include <cstring> #include <string.h> #include <iostream> #include <list> #include <map> #include <set> #include <stack> #include <string> #include <utility> #include <vector> #include <cstdio> #include <cmath> #define N 60005 #define INF 0x3ffffff using namespace std; const int matX = 2; typedef __int64 LL; const int mod = 1e9+7; const int maxn = 1e5 +10; LL ans; struct Matrix { int n, m; LL a[matX][matX]; Matrix() {} void init(int _n, int _m) { n = _n; m = _m; for(int i = 0; i < n; i++) { for(int j = 0; j < n; j++) a[i][j] = 0; } } Matrix operator + (const Matrix &B)const { Matrix C; C.init(n,m); for(int i=0; i<n; i++) for(int j=0; j<m; j++) C.a[i][j]=(a[i][j]+B.a[i][j])%mod; return C; } Matrix operator*(const Matrix &P)const { Matrix ret; ret.init(n,m); for(int i = 0; i < n; i++) { for(int k = 0; k < m; k++) { if(a[i][k]) { for(int j = 0; j < P.m; j++) { ret.a[i][j] = ((LL)a[i][k] * P.a[k][j] + ret.a[i][j]) % mod; } } } } return ret; } Matrix operator^(const LL &P)const { LL num = P; Matrix ret, tmp = *this; ret.init(n,m); for(int i = 0; i < n; i++) ret.a[i][i] = 1; while(num) { if(num & 1) ret = ret * tmp; tmp = tmp * tmp; num >>= 1; } return ret; } }; struct node { int l,r; Matrix add,sum; } s[maxn*4]; LL h[maxn]; void pushup(int x) { int tmp=x*2; s[x].sum=s[tmp].sum+s[tmp+1].sum; } bool judge(Matrix x) { for(int i=0;i<x.n;i++) for(int j=0;j<x.m;j++) if(x.a[i][j]) return false; return true; } void pushdown(int x) { if(judge(s[x].add)) return; int tmp=x*2; if(judge(s[tmp].add)) s[tmp].add=s[x].add;//这里原本是加法的,但是我们要维护乘法,所以要变成乘 else //同时还要考虑原矩阵是0矩阵的情况 s[tmp].add=s[tmp].add*s[x].add; if(judge(s[tmp+1].add)) s[tmp+1].add=s[x].add; else s[tmp+1].add=s[tmp+1].add*s[x].add; s[tmp].sum=s[x].add*s[tmp].sum; s[tmp+1].sum=s[x].add*s[tmp+1].sum; s[x].add.init(2,2); } void buildtree(int l,int r,int x) { s[x].l=l; s[x].r=r; s[x].add.init(2,2); s[x].sum.init(2,2); if(r==l) { Matrix as; as.init(2,2); as.a[0][0]=1; as.a[0][1]=1; as.a[1][0]=1; s[x].sum.a[0][0]=1; s[x].sum=(as^(h[l]-1))*s[x].sum; return; } int tmp=x<<1; int mid=(l+r)/2; buildtree(l,mid,tmp); buildtree(mid+1,r,tmp+1); pushup(x); } void query(int l,int r,int x) { if(s[x].l==l&&s[x].r==r) { ans+=s[x].sum.a[0][0]; ans%=mod; return ; } pushdown(x); int mid=(s[x].l+s[x].r)/2; if(r<=mid) query(l,r,2*x); else if(l>=mid+1) query(l,r,2*x+1); else { query(l,mid,2*x); query(mid+1,r,2*x+1); } } void updata(int l,int r,Matrix c,int x) { if(r<s[x].l||l>s[x].r) return; if(l<=s[x].l&&r>=s[x].r) { if(judge(s[x].add)) s[x].add=c; else s[x].add=c*s[x].add; s[x].sum=c*s[x].sum; return; } pushdown(x); int tmp=x*2; updata(l,r,c,tmp); updata(l,r,c,tmp+1); pushup(x); } int main() { int n,m,l,r,q; LL c; scanf("%d%d",&n,&m); for(int i=1; i<=n; i++) scanf("%I64d",&h[i]); buildtree(1,n,1); while(m--) { scanf("%d",&q); if(q==1) { scanf("%d%d%I64d",&l,&r,&c); Matrix as; as.init(2,2); as.a[0][0]=1; as.a[0][1]=1; as.a[1][0]=1; as=as^c; updata(l,r,as,1);//这里要把数字预处理矩阵带入,不然会被卡常 } else { scanf("%d%d",&l,&r); ans=0; query(l,r,1); printf("%I64d\n",(ans%mod+mod)%mod); } } return 0; }
Codeforces Round #373 (Div. 2)
标签:图片 const ios 数位 .com ide eve 斐波那契 def
原文地址:https://www.cnblogs.com/Agnel-Cynthia/p/10651577.html