###### 2016 UESTC Training for Data Structures

Input

1≤N≤100000
1≤Q≤100000
1≤p≤N
1≤x≤100000
1≤L≤R≤N

Output

5 4
2 1 2
1 2 4
1 3 5
2 3 3

0
5

Hint

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#define LiangJiaJun main
#define LL long long
using namespace std;
LL tr[400004];
int n,q,up=1;
LL  query(int l,int r){
LL ans=0;
for(l=l+up-1,r=r+up+1;r-l>1;r>>=1,l>>=1){
if(~(l&1)) ans=max(ans,tr[l+1]);
if(r&1) ans=max(ans,tr[r-1]);
}
return ans;
}
void change(int p,LL x){
int now = p + up ;
tr[now] += x;
now >>= 1;
while(now >= 1){
tr[now] =max( tr[now<<1] , tr[now<<1|1] );
now >>= 1;
}
}
int LiangJiaJun(){
scanf("%d%d",&n,&q);
while(up<n+2)up<<=1;
memset(tr,0,sizeof(tr));
while(q--){
int t,p,l,r;LL x;
scanf("%d",&t);
if(t==1){
scanf("%d%lld",&p,&x);
change(p,x);
}
if(t==2){
scanf("%d%d",&l,&r);
printf("%lld\n",query(l,r));
}
}
return 0;
}

Input

，表示村庄总共有N个人，村民从1开始编号到N
1≤N≤100000

Output

3
2 2
3 1
1 2

Time to show my power

3
2 2
3 2
1 2

One face meng bi

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<set>
#define LiangJiaJun main
#define LL long long
using namespace std;
bool ok=1;
int a[200004],t[200004],n;
int p,q,f[200014];
int find(int x){return (f[x] == x)?f[x]:f[x] = find(f[x]);}
int LiangJiaJun(){
scanf("%d",&n);
for(int i=1;i<=n;i++) scanf("%d%d",&a[i],&t[i]);
for(int i=1;i<=2*n;i++) f[i]=i;
for(int i=1;i<=n;i++){
if(t[i] == 1) {
p=find(i);q=find(a[i]);
if(p!=q)f[p]=q;
p=find(i+n);q=find(a[i]+n);
if(p!=q)f[p]=q;
}
else{
p=find(i);q=find(a[i]+n);
if(p!=q)f[p]=q;
p=find(i+n);q=find(a[i]);
if(p!=q)f[p]=q;
}
if(find(i)==find(i+n) || find(a[i])==find(a[i]+n)){ok=0;break;}
}
if(ok)puts("Time to show my power");
else puts("One face meng bi");
return 0;
}

“你的膜法也救不了你”——蛤

“少年，你渴望掌握雷电的力量吗？”天行廖如是问道。

Input

1≤N≤100000

1≤A[i],B[i]≤1000000000

Output

5
1 3 2 4 5
6 3 4 1 7

2
3
4
4
5

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<queue>
#define LiangJiaJun main
#define LL long long
#define pa pair<LL,int>
using namespace std;
priority_queue<pa , vector<pa> , greater<pa> >q;
LL A[100004],B[100004],ans[100004];
int n,qs[100004],cnt=0;
int LiangJiaJun(){
scanf("%d",&n);
for(int i=1;i<=n;i++)scanf("%lld",&A[i]);
for(int i=1;i<=n;i++)scanf("%lld",&B[i]);
sort(A+1,A+n+1);sort(B+1,B+n+1);
for(int i=1;i<=n;i++){
q.push(make_pair(A[1]+B[i],i));
qs[i] = 1;
}
cnt=0;
while(cnt <= n){
pa x = q.top();q.pop();
ans[++cnt] = x.first;
q.push(make_pair(A[++qs[x.second]]+B[x.second],x.second));
}
for(int i=1;i<=n;i++)printf("%lld\n",ans[i]);
return 0;
}

Rabi-Ribi呢，是一个打兔子的动作冒险游戏，萌萌哒的兔子在地上跑来跑去，好萌好萌呀~

Input

1≤N≤100000
1≤a[i]≤5000
1≤v[i]≤1000

Output

5
5 3 6 1 4
7 9 2 1 5

24

3
1 1 1
1 2 3

3

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<queue>
#define LiangJiaJun main
#define LL long long
#define pa pair<int,int>
using namespace std;
priority_queue<pa , vector<pa> , greater<pa> >q,qf;
int n,tn=0,ans=0;
struct data{
int w,t;
}a[100004];
int LiangJiaJun(){
scanf("%d",&n);
for(int i=1;i<=n;i++)scanf("%d",&a[i].t);
for(int i=1;i<=n;i++)scanf("%d",&a[i].w);
for(int i=1;i<=n;i++)q.push(make_pair(a[i].t,a[i].w));
while(!q.empty()){
pa x = q.top();q.pop();
if(x.first>tn){
tn ++;qf.push(make_pair(x.second,x.first));
}
else {
if(!qf.empty()&&x.second > qf.top().first){
qf.pop(); qf.push(make_pair(x.second,x.first));
}
}
}
ans = 0;
while(!qf.empty()){
ans += qf.top().first;
qf.pop();
}
printf("%d\n",ans);
return 0;
}

#### 【UESTC】2015 UESTC Training for Data Structures

2015-12-17 00:30:18

#### 2014 UESTC Training for Dynamic Programming

2014-06-02 12:00:15

#### UESTC Training for Data Structures——C

2012-05-02 21:19:02

#### UESTC Training for Data Structures——I

2012-05-02 21:27:03

#### UESTC Training for Data Structures——J

2012-05-02 21:28:13

#### UESTC Training for Data Structures——G

2012-05-02 21:24:38

#### 2018 UESTC Training for Data Structures--L - 爱吃瓜的伊卡洛斯(2) 启发式合并+并查集+set

2018-05-13 10:02:03

#### 2016 UESTC Training for Data Structures C - 卿学姐与诡异村庄 并查集

2016-05-01 00:01:50

#### UESTC Training for Data Structures——F

2012-05-02 21:23:20

#### 2016 UESTC Training for Data Structures J - 郭大侠与Rabi-Ribi CDOJ 1334 优先队列

2016-05-01 14:31:06

## 不良信息举报

2016 UESTC Training for Data Structures