http://codeforces.com/contest/66题目不是很难,为啥比赛时状态那么差...
A 判断BigInteger可以用string来判断就行了,不用大整数
B 水
C 建树
D我的那种构造方法肯定要大整数的,太懒了,居然不上java
E单调队列,之前做过类似的,sample画错... T_T
D
/**//*
构造n个数,使得两两不互素,但所有数互素
其实只要前3个数互素就行了!!!
后面的数随便构造,跟前面同一个,有gcd>1
如6 10 15
后面的就20,30
比赛时,很囧
我是用前面n个素数去构造
a[i] = pr[1]**p[n] / p[i]
早就超long long
我偷懒不想java,以为不会超 T_T
*/
#include<iostream>
#include<cstring>
#include<map>
#include<algorithm>
#include<stack>
#include<queue>
#include<cmath>
#include<string>
#include<cstdlib>
#include<vector>
#include<cstdio>
#include<set>
#include<list>
#include<numeric>
#include<cassert>
#include<ctime>
using namespace std;
int main()
{
#ifndef ONLINE_JUDGE
//freopen("in","r",stdin);
#endif
for(int n; ~scanf("%d", &n); ){
if(n <= 2){
cout<<-1<<endl;
continue;
}
cout<<6<<endl<<10<<endl<<15<<endl;
for(int i = 3 ; i < n ; i++){
cout<<10*(i-1)<<endl;
}
}
return 0;
}
E
/**//*
n个顶点连接成一个环 n<=10^6
在每个点出能加油a[i],i到i+1需耗油b[i]
问有多少个点可以作为起点,使得顺时针或逆时针可以走完一圈
可以走完一圈也即油要足够了
考虑顺时针的
令num[i] = a[i] - b[i]
sum[i] = ∑num[j] i<=j<=n
若点start可以作为起点,则必有
sum[start] - sum[start+1] >= 0
sum[start] - sum[start+2] >= 0
sum[start] - sum[start+n] >= 0
也即min{sum[start] - sum[j]} >= 0 , sum[start] - max{sum[j]} >= 0
start+1<=j<=start+n
对于式子sum[start] - max{sum[j]} >= 0 就可以用单调队列来做了
维护一个单调递减的序列,队首就是最大值了
跟hdu 3474类似
*/
#include<iostream>
#include<cstring>
#include<map>
#include<algorithm>
#include<stack>
#include<queue>
#include<cmath>
#include<string>
#include<cstdlib>
#include<vector>
#include<cstdio>
#include<set>
#include<list>
#include<numeric>
#include<cassert>
#include<ctime>
using namespace std;
const int MAXN = 100861;
int a[MAXN], b[MAXN];
int num[MAXN*2];
int dq[MAXN];
long long sum[MAXN*2];
bool can[MAXN];
int main()
{
#ifndef ONLINE_JUDGE
freopen("in","r",stdin);
#endif
for(int n; ~scanf("%d",&n); ){
for(int i = 1 ; i <= n ; i++){
scanf("%d",&a[i]);
}
for(int i = 1 ; i <= n ; i++){
scanf("%d",&b[i]);
}
fill(can+1, can+1+n, false);
//min{sum[i] - sum[j]} >= 0
//sum[i] - max{sum[j]} >= 0
//mantain a decreasing sequence
//clockwise
for(int i = 1 ; i <= n ; i++){
num[i] = num[i+n] = a[i] - b[i];
}
sum[2*n+1] = 0;
int front = 0, tail = 0;
for(int i = 2*n ; i > n ; i--){
sum[i] = sum[i+1] + num[i];
while( front < tail && sum[dq[tail-1]] <= sum[i] )tail--;
dq[tail++] = i;
}
for(int i = n ; i > 0 ; i--){
sum[i] = sum[i+1] + num[i];
while(front < tail && dq[front] > i + n )front++;
if(sum[dq[front]] <= sum[i]){
can[i] = true;
}
while( front < tail && sum[dq[tail-1]] <= sum[i] )tail--;
dq[tail++] = i;
}
//counter-clockwise
for(int i = 1 ; i <= n ; i++){//注意是a[i] - b[i-1] !!!
num[i] = num[i+n] = a[i] - b[i > 1 ? i - 1 : n];
}
sum[0] = 0;
front = 0, tail = 0;
for(int i = 1 ; i <= n ; i++){
sum[i] = sum[i-1] + num[i];
while( front < tail && sum[dq[tail-1]] <= sum[i] )tail--;
dq[tail++] = i;
}
for(int i = n+1 ; i <= 2*n ; i++){
sum[i] = sum[i-1] + num[i];
while(front < tail && dq[front] < i - n )front++;
if(sum[dq[front]] <= sum[i]){
can[i-n] = true;
}
while( front < tail && sum[dq[tail-1]] <= sum[i] )tail--;
dq[tail++] = i;
}
int ans = count(can+1,can+1+n,true);
printf("%d\n",ans);
bool blank = false;
for(int i = 1 ; i <= n ; i++){
if(can[i]){
if(blank){
putchar(' ');
}
printf("%d",i);
blank = true;
}
}
puts("");
}
return 0;
}