Codeforces 343
A:
不会做……
B:
看不懂题……
C:
二分答案顺序检验。
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include<cstdio>
2 #include<cstdlib>
3 #include<cstring>
4 #include<algorithm>
5
6 using namespace std;
7
8 const int maxn=100010;
9
10 int n,m;
11
12 long long z[maxn],y[maxn];
13
14 bool check(long long v)
15 {
16 int p=1;
17 for (int a=1;a<=n;a++)
18 if (p<=m)
19 {
20 if (y[p]<z[a])
21 {
22 if (y[p]+v<z[a]) return false;
23 long long r=max(max(y[p]+v-(z[a]-y[p]),z[a]),z[a]+max(0ll,(v-(z[a]-y[p]))>>1));
24 while (p<=m && y[p]<=r)
25 p++;
26 }
27 else
28 {
29 long long r=z[a]+v;
30 while (p<=m && y[p]<=r)
31 p++;
32 }
33 }
34 else return true;
35 return p>m;
36 }
37
38 int main()
39 {
40 scanf("%d%d",&n,&m);
41 for (int a=1;a<=n;a++)
42 scanf("%I64d",&z[a]);
43 for (int a=1;a<=m;a++)
44 scanf("%I64d",&y[a]);
45 if (n==m)
46 {
47 bool able=true;
48 for (int a=1;a<=n;a++)
49 if (z[a]!=y[a]) able=false;
50 if (able)
51 {
52 printf("0\n");
53 return 0;
54 }
55 }
56 long long l=0,r=z[n]+y[m]+1;
57 while (l+1!=r)
58 {
59 long long m=(l+r)>>1;
60 if (check(m)) r=m;
61 else l=m;
62 }
63 printf("%I64d\n",r);
64
65 return 0;
66 }
D:
三种操作是灌水、抽水和询问,拿两棵线段树分别维护灌水和抽水操作即可。
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include<cstdio>
2 #include<cstdlib>
3 #include<cstring>
4 #include<algorithm>
5
6 using namespace std;
7
8 #define lson l,m,rt<<1
9 #define rson m+1,r,rt<<1|1
10 #define wmt 1,n,1
11
12 const int maxn=500010;
13
14 int n,m,en,cnt,l[maxn],r[maxn],y[maxn<<2|1],z[maxn<<2|1];
15
16 struct edge
17 {
18 int e;
19 edge *next;
20 }*v[maxn],ed[maxn<<1];
21
22 void add_edge(int s,int e)
23 {
24 en++;
25 ed[en].next=v[s];v[s]=ed+en;v[s]->e=e;
26 }
27
28 void dfs(int now,int pre)
29 {
30 l[now]=++cnt;
31 for (edge *e=v[now];e;e=e->next)
32 if (e->e!=pre) dfs(e->e,now);
33 r[now]=cnt;
34 }
35
36 void build(int l,int r,int rt)
37 {
38 y[rt]=-1;z[rt]=0;
39 if (l==r) return;
40 int m=(l+r)>>1;
41 build(lson);
42 build(rson);
43 }
44
45 void modify1(int l,int r,int rt,int nowl,int nowr,int v)
46 {
47 if (nowl<=l && r<=nowr)
48 {
49 y[rt]=v;
50 return;
51 }
52 int m=(l+r)>>1;
53 if (nowl<=m) modify1(lson,nowl,nowr,v);
54 if (m<nowr) modify1(rson,nowl,nowr,v);
55 }
56
57 int query1(int l,int r,int rt,int p)
58 {
59 if (l==r) return y[rt];
60 int m=(l+r)>>1;
61 if (p<=m) return max(y[rt],query1(lson,p));
62 else return max(y[rt],query1(rson,p));
63 }
64
65 void modify2(int l,int r,int rt,int p,int v)
66 {
67 z[rt]=v;
68 if (l==r) return;
69 int m=(l+r)>>1;
70 if (p<=m) modify2(lson,p,v);
71 else modify2(rson,p,v);
72 }
73
74 int query2(int l,int r,int rt,int nowl,int nowr)
75 {
76 if (nowl<=l && r<=nowr) return z[rt];
77 int m=(l+r)>>1;
78 if (nowl<=m)
79 {
80 if (m<nowr) return max(query2(lson,nowl,nowr),query2(rson,nowl,nowr));
81 else return query2(lson,nowl,nowr);
82 }
83 else return query2(rson,nowl,nowr);
84 }
85
86 int main()
87 {
88 scanf("%d",&n);
89 for (int a=1;a<n;a++)
90 {
91 int s,e;
92 scanf("%d%d",&s,&e);
93 add_edge(s,e);
94 add_edge(e,s);
95 }
96 dfs(1,0);
97 build(wmt);
98 scanf("%d",&m);
99 for (int a=1;a<=m;a++)
100 {
101 int opt,p;
102 scanf("%d%d",&opt,&p);
103 if (opt==1) modify1(wmt,l[p],r[p],a);
104 else
105 {
106 if (opt==2) modify2(wmt,l[p],a);
107 else
108 {
109 int v1=query1(wmt,l[p]);
110 int v2=query2(wmt,l[p],r[p]);
111 if (v1>v2) printf("1\n");
112 else printf("0\n");
113 }
114 }
115 }
116
117 return 0;
118 }
E:
不会……