hdu多校 1004 1007 1010

Posted zzqc

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了hdu多校 1004 1007 1010相关的知识,希望对你有一定的参考价值。

Game

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 0    Accepted Submission(s): 0


Problem Description
Alice and Bob are playing a game.
The game is played on a set of positive integers from 1 to n.
In one step, the player can choose a positive integer from the set, and erase all of its divisors from the set. If a divisor doesn‘t exist it will be ignored.
Alice and Bob choose in turn, the one who cannot choose (current set is empty) loses.
Alice goes first, she wanna know whether she can win. Please judge by outputing ‘Yes‘ or ‘No‘.
 

 

Input
There might be multiple test cases, no more than 10. You need to read till the end of input.
For each test case, a line containing an integer n. (1n500)
 

 

Output
A line for each test case, ‘Yes‘ or ‘No‘.
 

 

Sample Input
1
 

 

Sample Output
Yes
 
  如果先手取1可以获胜就取1,如果取1之后后手取y可以获胜,那么先手取y就好了,留下的局面是一样的,所以无论如何先手必胜。
  
1 #include<bits/stdc++.h>
2 using namespace std;
3 int main(){
4     int n;
5     while(cin>>n){
6         puts("Yes");
7     }
8 }

 

 

Naive Operations

Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 502768/502768 K (Java/Others)
Total Submission(s): 0    Accepted Submission(s): 0


Problem Description
In a galaxy far, far away, there are two integer sequence a and b of length n.
b is a static permutation of 1 to n. Initially a is filled with zeroes.
There are two kind of operations:
1. add l r: add one for al,al+1...ar
2. query l r: query ri=l?ai/bi?
 


Input
There are multiple test cases, please read till the end of input file.
For each test case, in the first line, two integers n,q, representing the length of a,b and the number of queries.
In the second line, n integers separated by spaces, representing permutation b.
In the following q lines, each line is either in the form ‘add l r‘ or ‘query l r‘, representing an operation.
1n,q1000001lrn, there‘re no more than 5 test cases.
 


Output
Output the answer for each ‘query‘, each one line.
 


Sample Input
5 12 1 5 2 4 3 add 1 4 query 1 4 add 2 5 query 2 5 add 3 5 query 1 5 add 2 4 query 1 4 add 2 5 query 2 5 add 2 2 query 1 5
 


Sample Output
1 1 2 4 4 6
 
  区间[l,r]全部加1,或者询问SUM{ floor(a[i]/b[i]) | l<=i<=r}
  注意到并不是所有情况下a[i]加上1之后都会使得a[i]/b[i]的结果发生变化,所以我们用minb[b]维护区间最小的b值,
query时如果当前区间的minb不为<=0就可以直接使用之前计算的值,否则就递归左右儿子将minb的值累加到sum中。
  其实就是个线段树乱搞,当时没想到,唉太菜了。
  
 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 #define LL long long
 4 const int MAXN=100010; 
 5 int b[MAXN],n,m,l,r;
 6 char s[15];
 7 class ST{
 8     public:
 9     #define lc (id<<1)
10     #define rc (id<<1|1)
11     #define mid ((L+R)>>1)
12     
13     int minb[MAXN<<2],sum[MAXN<<2],laz[MAXN<<2];
14     
15     void pushup(int id){
16         sum[id]=sum[lc]+sum[rc];
17         minb[id]=min(minb[lc],minb[rc]);
18     }
19     void pushdown(int id,int L,int R){
20         if(laz[id]){
21             laz[lc]+=laz[id],minb[lc]-=laz[id];
22             laz[rc]+=laz[id],minb[rc]-=laz[id];
23             laz[id]=0;
24         }
25     }
26     void build(int id,int L,int R){
27         sum[id]=laz[id]=0;
28         if(L==R){
29             scanf("%d",b+L);
30             minb[id]=b[L];
31             return;
32         }
33         build(lc,L,mid);
34         build(rc,mid+1,R);
35         pushup(id);
36     }
37     void add(int id,int L,int R,int l,int r){
38         
39         if(L>=l&&R<=r){
40             laz[id]++;
41             minb[id]--;
42             return ;
43         }
44         pushdown(id,L,R);
45         if(l<=mid) add(lc,L,mid,l,r);
46         if(r>mid) add(rc,mid+1,R,l,r);
47         pushup(id);
48     }
49     int query(int id,int L,int R,int l,int r){
50         if(minb[id]>0&&L>=l&&R<=r){
51             return sum[id];
52         }
53         if(L==R){
54             if(minb[id]<=0){
55                 int d=(-minb[id]+b[L])/b[L];
56                 sum[id]+=d;
57                 minb[id]=b[L]-(-minb[id]/*+b[L]-d*b[L]*/)%b[L];
58             }
59             return sum[id];
60         }
61         else{
62             pushdown(id,L,R);
63             int s=0;
64             if(l<=mid) s+=query(lc,L,mid,l,r);
65             if(r>mid) s+=query(rc,mid+1,R,l,r);
66             pushup(id);
67             return s;
68         }
69     }
70 }a;
71 int main(){
72     while(scanf("%d%d",&n,&m)!=EOF){
73         a.build(1,1,n);
74         while(m--){
75             scanf("%s %d%d",s,&l,&r);
76             if(s[0]==a){
77                 a.add(1,1,n,l,r);
78             }
79             else{
80                 printf("%d
",a.query(1,1,n,l,r));
81             }
82         }
83     }
84     return 0;
85 }

 

 

 

Swaps and Inversions

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 0    Accepted Submission(s): 0


Problem Description
Long long ago, there was an integer sequence a.
Tonyfang think this sequence is messy, so he will count the number of inversions in this sequence. Because he is angry, you will have to pay x yuan for every inversion in the sequence.
You don‘t want to pay too much, so you can try to play some tricks before he sees this sequence. You can pay y yuan to swap any two adjacent elements.
What is the minimum amount of money you need to spend?
The definition of inversion in this problem is pair (i,j) which 1i<jn and ai>aj.
 


Input
There are multiple test cases, please read till the end of input file.
For each test, in the first line, three integers, n,x,y, n represents the length of the sequence.
In the second line, n integers separated by spaces, representing the orginal sequence a.
1n,x,y100000, numbers in the sequence are in [?109,109]. There‘re 10 test cases.
 


Output
For every test case, a single integer representing minimum money to pay.
 


Sample Input
3 233 666 1 2 3 3 1 666 3 2 1
 


Sample Output
0 3
 
  md,原来逆序对的数量就是使得数组变为有序的最少相邻元素交换次数,一开始并不知道这个原理,在纸上画了半天,最后写的时候发现了,哎这么弱智的东西搞了大半天。
  
 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 #define LL long long 
 4 int a[100010],b[100010];
 5 LL C[100010],n;
 6 map<int,int>M;
 7 set<int>S;
 8 set<int>::iterator it;
 9 int lowbit(int x){
10     return x&-x;
11 }
12 int sum(int x){
13     LL ret=0;
14     while(x>0){
15         ret+=C[x];
16         x-=lowbit(x);
17     }
18     return ret;
19 }
20 void add(int x,int d){
21     while(x<=n){
22         C[x]+=d;
23         x+=lowbit(x);
24     }
25 }
26 int main(){
27     int x,y,i,j,k;
28     while(cin>>n>>x>>y){
29         memset(C,0,sizeof(C));
30         M.clear();
31         S.clear();
32         LL ans=0;
33         for(i=1;i<=n;++i){
34             scanf("%d",a+i);
35             b[i]=a[i];
36         }
37         int tot=0;
38         sort(b+1,b+1+n);
39         for(i=1;i<=n;++i){
40             if(M[b[i]]) continue;
41             M[b[i]]=++tot;
42         }
43     
44         for(i=n;i>=1;--i){
45             ans+=sum(M[a[i]]-1);
46             add(M[a[i]],1);
47         }
48             cout<<ans*min(x,y)<<endl;
49     }
50     return 0;
51 }

 












































以上是关于hdu多校 1004 1007 1010的主要内容,如果未能解决你的问题,请参考以下文章

暑假N天乐比赛篇 —— 2019杭电暑期多校训练营(第五场)

hdu多校1004 Distinct Values

HDU6312 Game (多校第二场1004) 简单博弈

HDU6315 Naive Operations(多校第二场1007)(线段树)

hdu多校第五场1007 (hdu6630) permutation 2 dp

hdu多校第四场 1007 (hdu6620) Just an Old Puzzle 逆序对