http://codeforces.com/contest/1180/problems
B. Nick and Array
The meaning of problems: a given n-bit conversion so that the presence of a product becomes an -an-1 request after the maximum sequence of SEQ several transformed
This track title cards for a long time it should not be the main card at 0 and -1 point a lot of class
In fact, default can first of all becomes negative at this time if the number is even then that is the maximum value
If an odd number: the smallest negative to positive can be
#include<bits/stdc++.h> using namespace std; //input by bxd #define rep(i,a,b) for(int i=(a);i<=(b);i++) #define repp(i,a,b) for(int i=(a);i>=(b);--i) #define RI(n) scanf("%d",&(n)) #define RII(n,m) scanf("%d%d",&n,&m) #define RIII(n,m,k) scanf("%d%d%d",&n,&m,&k) #define RS(s) scanf("%s",s); #define ll long long #define see(x) (cerr<<(#x)<<'='<<(x)<<endl) #define pb push_back #define REP(i,N) for(int i=0;i<(N);i++) #define CLR(A,v) memset(A,v,sizeof A) ////////////////////////////////// #define inf 0x3f3f3f3f const int N=1e5+10; int n,m; struct node { int v,pos; }s[N]; bool cmp(node a,node b) { return a.v<b.v; } bool cmp2(node a,node b) { return a.pos<b.pos; } int main () { RI (n); rep(i,1,n) { int x;RI(x);if(x>=0)x=-x-1; s[i].v=x;s[i].pos=i; } if(n%2==0) { rep(i,1,n) printf("%d ",s[i].v); } else { sort(s+1,s+1+n,cmp); s[1].v=-s[1].v-1; sort(s+1,s+1+n,cmp2); rep(i,1,n) printf("%d ",s[i].v); } return 0; }
The meaning of problems: given a sequence of m n number of interrogation
This sequence was considered deque withdrawn from scratch each time a large number of two in the small front AB
Asked the k-th out of which two numbers
And initially a bit analog to find loop section. . . Wasting some time
In fact, when the largest in the head section of the cycle has ended for the n-1 and then simulate what you can
#include<bits/stdc++.h> using namespace std; //input by bxd #define rep(i,a,b) for(int i=(a);i<=(b);i++) #define repp(i,a,b) for(int i=(a);i>=(b);--i) #define RI(n) scanf("%d",&(n)) #define RII(n,m) scanf("%d%d",&n,&m) #define RIII(n,m,k) scanf("%d%d%d",&n,&m,&k) #define RS(s) scanf("%s",s); #define ll long long #define see(x) (cerr<<(#x)<<'='<<(x)<<endl) #define pb push_back #define REP(i,N) for(int i=0;i<(N);i++) #define CLR(A,v) memset(A,v,sizeof A) ////////////////////////////////// #define inf 0x3f3f3f3f const int N=3e5+10; int n,m,x,maxx,ans[N][2],A,B,cnt; and < int > q; ll qe[N]; int main () { RII (n, m); int T=n-1; rep(i,1,n) { RI (x); q.push_back(x); maxx=max(maxx,x); } cnt=0; while(1) { ++cnt; A=q.front();q.pop_front(); B=q.front();q.pop_front(); years [cnt] [ 0 ] = A, years [cnt] [ 1 ] = B; if (A> B) q.push_front(A),q.push_back(B); else q.push_back(A),q.push_front(B); if(q.front()==maxx){break;} } int cnt2=cnt; rep(i,1,T) { ++ cnt2; A=q.front();q.pop_front(); B=q.front();q.pop_front(); years [cnt2] [ 0 ] = A, years [cnt2] [ 1 ] = B; if (A> B) q.push_front(A),q.push_back(B); else q.push_back(A),q.push_front(B); } rep(i,1,m) { scanf("%lld",&qe[i]); if(qe[i]<=cnt2)printf("%d %d\n",ans[qe[i]][0],ans[qe[i]][1]); else { that [i] = (to [i] -cnt)% T; f (! that [i]) to [i] = T; printf("%d %d\n",ans[ qe[i]+cnt ][0],ans[qe[i]+cnt][1]); } } return 0; }
D. Tolik and His Uncle
The meaning of problems: Given a matrix of n * m traversing a lattice in all 11 seeking method requires any further if the same vector can not walk output could not finish -1
Obviously one side while alternately from 11 snake is the answer from nm go
Note the case of grid parity
#include<bits/stdc++.h> using namespace std; //input by bxd #define rep(i,a,b) for(int i=(a);i<=(b);i++) #define repp(i,a,b) for(int i=(a);i>=(b);--i) #define RI(n) scanf("%d",&(n)) #define RII(n,m) scanf("%d%d",&n,&m) #define RIII(n,m,k) scanf("%d%d%d",&n,&m,&k) #define RS(s) scanf("%s",s); #define ll long long #define see(x) (cerr<<(#x)<<'='<<(x)<<endl) #define pb push_back #define REP(i,N) for(int i=0;i<(N);i++) #define CLR(A,v) memset(A,v,sizeof A) ////////////////////////////////// #define inf 0x3f3f3f3f const int N=3e5+10; int n,m; int main() { RII (n, m); int x=1,y=1,d1=1,x2=n,y2=m,d2=-1; if(n==1&&m==1){printf("1 1");return 0;} int X=n+1,Y=m+1; ll cnt=n*m; ll temp=cnt/2; while( temp--) { printf("%d %d\n",x,y); printf("%d %d\n",X-x,Y-y); y+=d1; if(y==m+1) { y=m;d1=-d1;x++; } if(y==0) { y=1;d1=-d1;x++; } } if(cnt%2==1) printf("%d %d",x,y); return 0; }
This question output reaches 1000 c ^ 2 tested faster than c ++ (++ closed flow course c)
<< endl << '\ n' former timeout latter not time out
#include<bits/stdc++.h> using namespace std; //input by bxd #define rep(i,a,b) for(int i=(a);i<=(b);i++) #define repp(i,a,b) for(int i=(a);i>=(b);--i) #define RI(n) scanf("%d",&(n)) #define RII(n,m) scanf("%d%d",&n,&m) #define RIII(n,m,k) scanf("%d%d%d",&n,&m,&k) #define RS(s) scanf("%s",s); #define ll long long #define see(x) (cerr<<(#x)<<'='<<(x)<<endl) #define pb push_back #define REP(i,N) for(int i=0;i<(N);i++) #define CLR(A,v) memset(A,v,sizeof A) ////////////////////////////////// #define inf 0x3f3f3f3f const int N=3e5+10; int n,m; int main() { RII (n, m); int x=1,y=1,d1=1,x2=n,y2=m,d2=-1; if(n==1&&m==1){printf("1 1");return 0;} int X=n+1,Y=m+1; ll cnt=n*m; ll temp=cnt/2; while( temp--) { printf("%d %d\n",x,y); printf("%d %d\n",X-x,Y-y); y+=d1; if(y==m+1) { y=m;d1=-d1;x++; } if(y==0) { y=1;d1=-d1;x++; } } if(cnt%2==1) printf("%d %d",x,y); return 0; }
The final rank 270 although playing very smelly but actually the best score in history the QAQ