This commit is contained in:
Saturneric 2020-09-01 00:49:54 +08:00
parent cece7a8368
commit 5f1e83651d
20 changed files with 289 additions and 0 deletions

BIN
2182/main Normal file

Binary file not shown.

70
2182/main.c Normal file
View File

@ -0,0 +1,70 @@
#include <stdio.h>
#define MAX 8005
struct node {
int from, to;
int value;
};
int cows[MAX];
struct node tree[4*MAX];
int build_tree(struct node *tree, long idx, int from, int to);
int find_section(struct node *tree, long idx, int spn);
int upd_tree(struct node *tree, long idx, int tidx);
int main(void){
int n;
scanf("%d",&n);
build_tree(tree, 0, 1, n);
cows[0] = 0;
for(int i = 1; i < n; i++){
scanf("%d",cows+i);
}
for(int i = n-1; ~i; i--){
int idx = find_section(tree, 0, cows[i]);
cows[i] = idx;
upd_tree(tree, 0, idx);
}
for(int i = 0; i < n; i++) printf("%d\n",cows[i]);
return 0;
}
int build_tree(struct node *tree, long idx, int from, int to){
int h_idx = (from + to)/2;
tree[idx].from = from;
tree[idx].to = to;
tree[idx].value = 0;
if(from < to){
build_tree(tree, idx*2+1, from, h_idx);
build_tree(tree, idx*2+2, h_idx+1, to);
tree[idx].value = tree[idx*2+1].value + tree[idx*2+2].value;
}
else{
tree[idx].value = 1;
}
return 0;
}
int find_section(struct node *tree, long idx, int spn){
if(tree[idx].from == tree[idx].to){
return tree[idx].from;
}
if(tree[idx*2+1].value <= spn){
return find_section(tree, idx*2+2, spn-tree[idx*2+1].value);
}
else{
return find_section(tree, idx*2+1, spn);
}
}
int upd_tree(struct node *tree, long idx, int tidx){
int h_idx = (tree[idx].from + tree[idx].to)/2;
tree[idx].value--;
if(tree[idx].from < tree[idx].to){
if(tidx <= h_idx) upd_tree(tree, idx*2+1, tidx);
else upd_tree(tree, idx*2+2, tidx);
}
return 0;
}

0
2182/problem.set Normal file
View File

0
2182/stdin Normal file
View File

0
2182/stdout Normal file
View File

67
2352/main.c Normal file
View File

@ -0,0 +1,67 @@
#include<stdio.h>
#define MAX (15000+5L)
struct node{
int from, to;
int n;
};
int rank[MAX];
struct node tree[32000*4L];
int build_tree(struct node *tree, long idx, int from , int to);
int upd_tree(struct node *tree, long idx, int p_idx);
int find_section(struct node *tree, long idx, int from, int to);
int main(void){
int number, i;
build_tree(tree, 0, 0, 32000);
scanf("%d",&number);
for(i = 0; i < number; i++){
int x,y;
scanf("%d %d",&x,&y);
rank[find_section(tree, 0, 0, x)]++;
upd_tree(tree, 0, x);
}
for(i = 0; i < number; i++){
printf("%d\n",rank[i]);
}
return 0;
}
int build_tree(struct node *tree, long idx, int from , int to){
int h_idx = (from+to)/2;
tree[idx].from = from;
tree[idx].to = to;
tree[idx].n = 0;
if(from < to){
build_tree(tree, idx*2+1, from, h_idx);
build_tree(tree, idx*2+2, h_idx+1, to);
}
return 0;
}
int upd_tree(struct node *tree, long idx, int p_idx){
int h_idx = (tree[idx].from + tree[idx].to)/2;
tree[idx].n++;
if(tree[idx].from < tree[idx].to){
if(p_idx <= h_idx) upd_tree(tree, idx*2+1, p_idx);
else upd_tree(tree, idx*2+2, p_idx);
}
return 0;
}
int find_section(struct node *tree, long idx, int from, int to){
int h_idx = (tree[idx].from + tree[idx].to)/2, sum = 0;
if(tree[idx].from == from && tree[idx].to == to) return tree[idx].n;
if(from <= h_idx && to > h_idx)
sum = find_section(tree, idx*2+1, from, h_idx) + find_section(tree, idx*2+2, h_idx+1, to);
else if(from <= h_idx && to <= h_idx)
sum = find_section(tree, idx*2+1, from , to);
else if(from > h_idx && to > h_idx)
sum = find_section(tree, idx*2+2, from , to);
else printf("IMP!\n");
return sum;
}

BIN
2352/problem.build Normal file

Binary file not shown.

0
2352/problem.set Normal file
View File

6
2352/stdin Normal file
View File

@ -0,0 +1,6 @@
5
1 1
5 1
7 1
3 3
5 5

5
2352/stdout Normal file
View File

@ -0,0 +1,5 @@
1
2
1
1
0

75
2828/main.c Normal file
View File

@ -0,0 +1,75 @@
#include <stdio.h>
#define MAX 200005
struct node {
long from, to;
int value;
};
long peo[MAX],num[MAX],line[MAX];
struct node tree[4*MAX];
int build_tree(struct node *tree, long idx, long from, long to);
long find_section(struct node *tree, long idx, long spn);
int upd_tree(struct node *tree, long idx, long tidx);
int main(void){
int n;
while(scanf("%d",&n) != EOF){
build_tree(tree, 0, 1, n);
for(int i = 0; i < n; i++){
scanf("%ld %ld",peo+i, num+i);
}
for(int i = n-1; ~i; i--){
long idx = find_section(tree, 0, peo[i]);
line[idx-1] = num[i];
upd_tree(tree, 0, idx);
}
for(int i = 0; i < n; i++){
if(i) printf(" ");
printf("%ld",line[i]);
}
printf("\n");
}
return 0;
}
int build_tree(struct node *tree, long idx, long from, long to){
long h_idx = (from + to)/2;
tree[idx].from = from;
tree[idx].to = to;
tree[idx].value = 0;
if(from < to){
build_tree(tree, idx*2+1, from, h_idx);
build_tree(tree, idx*2+2, h_idx+1, to);
tree[idx].value = tree[idx*2+1].value + tree[idx*2+2].value;
}
else{
tree[idx].value = 1;
}
return 0;
}
long find_section(struct node *tree, long idx, long spn){
if(tree[idx].from == tree[idx].to){
return tree[idx].from;
}
if(tree[idx*2+1].value <= spn){
return find_section(tree, idx*2+2, spn-tree[idx*2+1].value);
}
else{
return find_section(tree, idx*2+1, spn);
}
}
int upd_tree(struct node *tree, long idx, long tidx){
long h_idx = (tree[idx].from + tree[idx].to)/2;
tree[idx].value--;
if(tree[idx].from < tree[idx].to){
if(tidx <= h_idx) upd_tree(tree, idx*2+1, tidx);
else upd_tree(tree, idx*2+2, tidx);
}
return 0;
}

BIN
2828/problem.build Normal file

Binary file not shown.

0
2828/problem.set Normal file
View File

0
2828/stdin Normal file
View File

0
2828/stdout Normal file
View File

66
3264/main.c Normal file
View File

@ -0,0 +1,66 @@
#include <stdio.h>
#define MAX (50000+5L)
struct node{
int from ,to;
long height;
};
long cows[MAX];
struct node hi[MAX*4], lo[MAX*4];
int build_tree(struct node *tree, long *cows, long idx, int from, int to, int hol);
long find_selection(struct node *tree, long idx, int from, int to, int hol);
int main(void){
long nc,nm;
printf("INPUT:\n");
scanf("%ld %ld",&nc,&nm);
for(long i = 0; i < nc; i++) scanf("%ld",cows+i);
build_tree(hi, cows, 0, 1, (int)nc, 0);
build_tree(lo, cows, 0, 1, (int)nc, 1);
for(long i = 0; i < nm; i++){
int idxa, idxb;
scanf("%d %d",&idxa,&idxb);
long hh = find_selection(hi, 0, idxa, idxb, 0);
long lh = find_selection(lo, 0, idxa, idxb, 1);
printf("%ld\n",hh-lh);
}
return 0;
}
int build_tree(struct node *tree, long *cows, long idx, int from, int to, int hol){
int h_idx = (from + to)/2;
tree[idx].from = from;
tree[idx].to = to;
if(from < to){
build_tree(tree, cows, idx*2+1, from, h_idx, hol);
build_tree(tree, cows, idx*2+2, h_idx+1, to, hol);
long l = tree[idx*2+1].height, r = tree[idx*2+2].height;
if(hol == 0) tree[idx].height = r>l?r:l;
else tree[idx].height = r>l?l:r;
}
else{
tree[idx].height = cows[from-1];
}
return 0;
}
long find_selection(struct node *tree, long idx, int from, int to, int hol){
int h_idx = (tree[idx].from + tree[idx].to)/2;
if(from == tree[idx].from && to == tree[idx].to) return tree[idx].height;
if(from <= h_idx && to > h_idx){
long l = find_selection(tree, idx*2+1, from, h_idx, hol), r = find_selection(tree, idx*2+2, h_idx+1, to, hol);
if(hol == 0) return r>l?r:l;
else return r>l?l:r;
}
else if(from <= h_idx && to <= h_idx){
return find_selection(tree, idx*2+1, from, to, hol);
}
else if (from > h_idx && to > h_idx){
return find_selection(tree, idx*2+2, from, to, hol);
}
return 0;
}

BIN
3264/problem.build Normal file

Binary file not shown.

0
3264/problem.set Normal file
View File

0
3264/stdin Normal file
View File

0
3264/stdout Normal file
View File