Preface
Randomly challenge Part1Part1Part1 is to give up and finish the topic in 10 days...
This sum WYCdalao and XXYdalao Another random challenge.
This time, everyone was randomly jumping three blue questions in Luogu.
Results the two men beat me by hanging qwqwqqwq, 8h8h8h earlier than me.
It's still too much.
subject
- P4231P4231P4231 three step kill
- P2841 A×B ProblemP2841\ A\times B\ ProblemP2841 A×B Problem
-
P5097 [USACO2004OPEN]Cave ' covers ' 2p5097 \ [USACO2004OPEN]Cave \ covers \ 2p5097 [USACO2004OPEN]Cave ' covers ' 2
Summary of the other two random challenges: WYCdalao : XXYdalao
T1T1T1 is a group with good difference and small code size.
T2T2T2 stupid bfsbfsbfs + high precision questions, small code size.
T3T3T3 * * question, pure bare line tree template, has not been modified yet. I was judged blue...
Title Solution
T1 P4231P4231P4231 three step kill
Stamp me: Link\color{blue}\texttt {stamp me: Link} stamp me: Link
T2 P2841 A×B ProblemP2841\ A\times B\ ProblemP2841 A×B Problem
Poke me: Link\color{green}\texttt {poke me: Link} poke me: Link
T3 P5097 [USACO2004OPEN]Cave ' covers ' 2p5097 \ [USACO2004OPEN]Cave \ covers \ 2p5097 [USACO2004OPEN]Cave ' covers ' 2
Didn't write the explanation... What is there to write about the line tree template?
Or just put a link to the segment tree template?
Poke me: Link\color{red}\texttt {poke me: Link} poke me: Link
Code
T1
#include <cstdio> #include <string> #include <algorithm> using namespace std; typedef long long ll; const int N=1e7+10; int n,m,l,r; ll a[N],sum[N],add,x,y,ans1,ans2; ll read() { ll d=0; char ch=getchar(); while (!isdigit(ch)) ch=getchar(); while (isdigit(ch)) d=(d<<3)+(d<<1)+ch-48,ch=getchar(); return d; } int main() { n=(int)read(); m=(int)read(); for (int i=1;i<=m;i++) { l=(int)read(); r=(int)read(); x=read(); y=read(); add=(y-x)/(ll)(r-l); a[l]+=x; a[l+1]+=add-x; a[r+1]-=add+y; a[r+2]+=y; } for (int i=1;i<=n;i++) { sum[i]=sum[i-1]+a[i]; a[i]=a[i-1]+sum[i]; ans1^=a[i]; ans2=max(ans2,a[i]); } printf("%lld %lld\n",ans1,ans2); return 0; }
T2
#include <queue> #include <cstdio> using namespace std; const int N=10010,M=200; int n,a[N]; bool hash[N],flag; struct node { int a[M+1],p,len; }ans1,ans2; queue<node> q; node xx; void bfs() { xx.len=1; xx.a[1]=1; xx.p=1; q.push(xx); hash[1]=1; while (q.size()) { node u=q.front(); q.pop(); if (!u.p) { ans1=ans2=u; return; } for (int i=0;i<=1;i++) { int p=(u.p*10+i)%n; if (!hash[p]) { hash[p]=1; node v=u; v.len++; v.a[v.len]=i; v.p=p; q.push(v); } } } } int main() { scanf("%d",&n); if (n==1) return !printf("1 1\n"); bfs(); for (int i=1;i<=ans1.len;i++) { a[i]=ans1.a[i]/n; ans1.a[i+1]+=ans1.a[i]%n*10; } int i=1; while (!a[i]) i++; for (;i<=ans2.len;i++) printf("%d",a[i]); putchar(32); for (i=1;i<=ans2.len;i++) printf("%d",ans2.a[i]); return 0; }
T3
#include <cstdio> #include <algorithm> using namespace std; const int N=25010; int n,m,a[N],l,r; struct Tree { int l,r,minn; }tree[N*4]; void build(int x) { if (tree[x].l==tree[x].r) { tree[x].minn=a[tree[x].l]; return; } int mid=(tree[x].l+tree[x].r)/2; tree[x*2].l=tree[x].l; tree[x*2].r=mid; tree[x*2+1].l=mid+1; tree[x*2+1].r=tree[x].r; build(x*2); build(x*2+1); tree[x].minn=min(tree[x*2].minn,tree[x*2+1].minn); } int ask(int x,int l,int r) { if (l==tree[x].l && r==tree[x].r) return tree[x].minn; int mid=(tree[x].l+tree[x].r)/2; if (r<=mid) return ask(x*2,l,r); if (l>mid) return ask(x*2+1,l,r); return min(ask(x*2,l,mid),ask(x*2+1,mid+1,r)); } int main() { scanf("%d%d",&n,&m); for (int i=1;i<=n;i++) scanf("%d",&a[i]); tree[1].l=1; tree[1].r=n; build(1); while (m--) { scanf("%d%d",&l,&r); printf("%d\n",ask(1,l,r)); } return 0; }