徐州是真的心态崩了啊,绝望的比赛,邀请赛还是拿了一个名额的,怎么不会时光倒流啊,我真菜,赛后看看榜也挺绝望的
After Incident, a feast is usually held in Hakurei Shrine. This time Reimu asked Kokoro to deliver a Nogaku show during the feast. To enjoy the show, every audience has to wear a Nogaku mask, and seat around as a circle.
There are N guests Reimu serves. Kokoro has 2^k2k masks numbered from 0,1,cdots,0,1,⋯, 2^k - 12k−1, and every guest wears one of the masks. The masks have dark power of Dark Nogaku, and to prevent guests from being hurt by the power, two guests seating aside must ensure that if their masks are numbered ii and jj , then ii XNOR jj must be positive. (two guests can wear the same mask). XNOR means ~(ii^jj) and every number has kk bits. (11XNOR 1 = 11=1, 00 XNOR 0 = 10=1, 11 XNOR 0 = 00=0)
You may have seen 《A Summer Day's dream》, a doujin Animation of Touhou Project. Things go like the anime, Suika activated her ability, and the feast will loop for infinite times. This really troubles Reimu: to not make her customers feel bored, she must prepare enough numbers of different Nogaku scenes. Reimu find that each time the same guest will seat on the same seat, and She just have to prepare a new scene for a specific mask distribution. Two distribution plans are considered different, if any guest wears different masks.
In order to save faiths for Shrine, Reimu have to calculate that to make guests not bored, how many different Nogaku scenes does Reimu and Kokoro have to prepare. Due to the number may be too large, Reimu only want to get the answer modules 1e9+71e9+7 . Reimu did never attend Terakoya, so she doesn't know how to calculate in module. So Reimu wishes you to help her figure out the answer, and she promises that after you succeed she will give you a balloon as a gift.
Input
First line one number TT , the number of testcases; (T le 20)(T≤20) .
Next TT lines each contains two numbers, NN and k(0<N, k le 1e6)k(0<N,k≤1e6) .
Output
For each testcase output one line with a single number of scenes Reimu and Kokoro have to prepare, the answer modules 1e9+71e9+7 .
样例输入
2 3 1 4 2
样例输出
2 84
题目来源
A这个函数,你变换一下就是不让相邻的数的非异或和为0,你把问题反过来,就是相邻的异或值为2^k-1
考虑第一个数有2^k种方法,第二个数就有2^k-1种,第n个数有2^k-2种
然后第一个和最后一个还要相邻,所以呢,你可以把漏算的情况考虑一下,就是第1个数和第(n-1)个数相同,所以公式就都有了
#include<stdio.h> #include<bits/stdc++.h> using namespace std; #define ll long long #define lson l,(l+r)/2,rt<<1 #define rson (l+r)/2+1,r,rt<<1|1 #define dbg(x) cout<<#x<<" = "<< (x)<< endl #define pb push_back #define fi first #define se second #define sz(x) (int)(x).size() #define pll pair<long long,long long> #define pii pair<int,int> #define pq priority_queue const int N=1e5+5,MD=1e9+7,INF=0x3f3f3f3f; const ll LL_INF=0x3f3f3f3f3f3f3f3f; const double eps=1e-9,e=exp(1),PI=acos(-1.); ll POW(ll x,ll y) { ll ans=1; for(;y;x=x*x%MD,y>>=1)if(y&1)ans=ans*x%MD; return ans; } int main() { ios::sync_with_stdio(false),cin.tie(0),cout.tie(0); int T; cin>>T; while(T--) { int n,k; cin>>n>>k; ll t1=POW(2,k),t2=(t1-1+MD)%MD,t2_inv=POW(t2,MD-2),t3=(t1-2+MD)%MD; ll sum=t1; for(int i=2;i<=n;i++)sum=sum*t2%MD; ll ans=sum; for(int i=2;i<=n;i++) { sum=sum*t2_inv%MD; if(i&1)ans=(ans-sum*t3%MD)%MD; } cout<<(ans+MD)%MD<<" "; } return 0; }
B. BE, GE or NE
In a world where ordinary people cannot reach, a boy named "Koutarou" and a girl named "Sena" are playing a video game. The game system of this video game is quite unique: in the process of playing this game, you need to constantly face the choice, each time you choose the game will provide 1-31−3options, the player can only choose one of them. Each option has an effect on a "score" parameter in the game.Some options will increase the score, some options will reduce the score, and some options will change the score to a value multiplied by -1−1 .
That is, if there are three options in a selection, the score will be increased by 11, decreased by 11, or multiplied by -1−1. The score before the selection is 88. Then selecting option 11 will make the score become 99, and selecting option 22 will make the score 77 and select option 33 to make the score -8−8. Note that the score has an upper limit of 100100 and a lower limit of -100−100. If the score is 9999at this time, an option that makes the score +2+2 is selected. After that, the score will change to 100100 and vice versa .
After all the choices have been made, the score will affect the ending of the game. If the score is greater than or equal to a certain value kk, it will enter a good ending; if it is less than or equal to a certain value ll, it will enter the bad ending; if both conditions are not satisfied, it will enter the normal ending. Now, Koutarou and Sena want to play the good endings and the bad endings respectively. They refused to give up each other and finally decided to use the "one person to make a choice" way to play the game, Koutarou first choose. Now assume that they all know the initial score, the impact of each option, and the kk, ll values, and decide to choose in the way that works best for them. (That is, they will try their best to play the ending they want. If it's impossible, they would rather normal ending than the ending their rival wants.)
Koutarou and Sena are playing very happy, but I believe you have seen through the final ending. Now give you the initial score, the kk value, the ll value, and the effect of each option on the score. Can you answer the final ending of the game?
Input
The first line contains four integers n,m,k,ln,m,k,l(1le n le 10001≤n≤1000, -100 le m le 100−100≤m≤100 , -100 le l < k le 100−100≤l<k≤100 ), represents the number of choices, the initial score, the minimum score required to enter a good ending, and the highest score required to enter a bad ending, respectively.
Each of the next nn lines contains three integers a,b,ca,b,c(age 0a≥0 , bge0b≥0 ,c=0c=0or c=1c=1),indicates the options that appear in this selection,in which a=0a=0means there is no option to increase the score in this selection, a>0a>0 means there is an option in this selection to increase the score by aa ; b=0b=0 means there is no option to decrease the score in this selection, b>0b>0 means there is an option in this selection to decrease the score by bb; c=0c=0 means there is no option to multiply the score by -1−1 in this selection , c=1c=1 means there is exactly an option in this selection to multiply the score by -1−1. It is guaranteed that a,b,ca,b,c are not equal to 00 at the same time.
Output
One line contains the final ending of the game. If it will enter a good ending,print "Good Ending"
(without quotes); if it will enter a bad ending,print "Bad Ending"
(without quotes);otherwise print "Normal Ending"
(without quotes).
样例输入1
3 -8 5 -5 3 1 1 2 0 1 0 2 1
样例输出1
Good Ending
样例输入2
3 0 10 3 0 0 1 0 10 1 0 2 1
样例输出2
Bad Ending
题目来源
B是一个模拟题吧,你把所有情况都列出来,然后记忆化一下
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int N=1005; int down,up; int s,n; int a[N],b[N],c[N],dp[N][305]; int R,L; map<int,int>id; int dfs(int pos,int now) { if(pos==n+1) { if(now>=R) return 2; else if(now>L) return 1; return 0; } if(dp[pos][id[now]]!=-1) return dp[pos][id[now]]; if(pos&1) { int f=0; if(a[pos])f=max(f,dfs(pos+1,min(now+a[pos],up))); if(b[pos])f=max(f,dfs(pos+1,max(now+b[pos],down))); if(c[pos])f=max(f,dfs(pos+1,-now)); return dp[pos][id[now]]=f; } else { int f=2; if(a[pos])f=min(f,dfs(pos+1,min(now+a[pos],up))); if(b[pos])f=min(f,dfs(pos+1,max(now+b[pos],down))); if(c[pos])f=min(f,dfs(pos+1,-now)); return dp[pos][id[now]]=f; } } int main() { int tot=0; for(int i=-100; i<=100; i++) id[i]=++tot; down=-100,up=100; scanf("%d%d%d%d",&n,&s,&R,&L); for(int i=1; i<=n; i++)scanf("%d%d%d",&a[i],&b[i],&c[i]),b[i]=-b[i]; memset(dp,-1,sizeof(dp)); int f=dfs(1,s); if(f==2)printf("Good Ending "); else if(f==1)printf("Normal Ending "); else printf("Bad Ending "); return 0; }
F. Features Track
Morgana is learning computer vision, and he likes cats, too. One day he wants to find the cat movement from a cat video. To do this, he extracts cat features in each frame. A cat feature is a two-dimension vector <xx, yy>. If x_ixi = x_jxj and y_iyi = y_jyj, then <x_ixi, y_iyi> <x_jxj, y_jyj> are same features.
So if cat features are moving, we can think the cat is moving. If feature <aa, bb> is appeared in continuous frames, it will form features movement. For example, feature <aa , bb > is appeared in frame 2,3,4,7,82,3,4,7,8, then it forms two features movement 2-3-42−3−4 and 7-87−8 .
Now given the features in each frames, the number of features may be different, Morgana wants to find the longest features movement.
Input
First line contains one integer T(1 le T le 10)T(1≤T≤10) , giving the test cases.
Then the first line of each cases contains one integer nn (number of frames),
In The next nn lines, each line contains one integer k_iki ( the number of features) and 2k_i2ki intergers describe k_iki features in ith frame.(The first two integers describe the first feature, the 33rd and 44th integer describe the second feature, and so on).
In each test case the sum number of features NN will satisfy N le 100000N≤100000 .
Output
For each cases, output one line with one integers represents the longest length of features movement.
样例输入
1 8 2 1 1 2 2 2 1 1 1 4 2 1 1 2 2 2 2 2 1 4 0 0 1 1 1 1 1 1
样例输出
3
题目来源
直接01滚动
#include<bits/stdc++.h> using namespace std; int dp[2][100005]; map<int,long long> ma[2]; int main() { int T,n; scanf("%d",&T); while(T--) { memset(dp,0,sizeof dp); ma[0].clear(),ma[1].clear(); scanf("%d",&n); int cnt=0,maxx=0; for(int i=1,k;i<=n;i++) { scanf("%d",&k); for(int j=0;j<100005;j++) dp[cnt][j]=0; ma[cnt].clear(); for(int j=1,a,b;j<=k;j++) { scanf("%d%d",&a,&b); long long has=1LL*a*(1e9+7)+b; ma[cnt][has]=j; dp[cnt][j]=dp[cnt^1][ma[cnt^1][has]]+1; maxx=max(maxx,dp[cnt][j]); } cnt^=1; } printf("%d ",maxx); } return 0; }
G. Trace
There's a beach in the first quadrant. And from time to time, there are sea waves. A wave ( xx , yy ) means the wave is a rectangle whose vertexes are ( 00 , 00), ( xx , 00 ), ( 00 , yy ), ( xx , yy ). Every time the wave will wash out the trace of former wave in its range and remain its own trace of ( xx , 00 ) -> ( xx , yy ) and ( 00 , yy ) -> ( xx , yy ). Now the toad on the coast wants to know the total length of trace on the coast after n waves. It's guaranteed that a wave will not cover the other completely.
Input
The first line is the number of waves n(n le 50000)n(n≤50000).
The next nn lines,each contains two numbers xx yy ,( 0 < x0<x , y le 10000000y≤10000000),the ii-th line means the ii-th second there comes a wave of ( xx , yy ), it's guaranteed that when 1 le i1≤i , j le nj≤n ,x_i le x_jxi≤xj and y_i le y_jyi≤yj don't set up at the same time.
Output
An Integer stands for the answer.
Hint:
As for the sample input, the answer is 3+3+1+1+1+1=103+3+1+1+1+1=10
样例输入
3 1 4 4 1 3 3
样例输出
10
题目来源
就是因为G自闭了啊,不懂怎么时光倒流
其实只差一点
#include<bits/stdc++.h> using namespace std; const int N=50005; int n,m,x[N],y[N]; int main() { cin>>n; for(int i=0; i<n; i++)scanf("%d%d",&x[i],&y[i]); long long ans=0; set<int> sx,sy; set<int>::iterator itx,ity; for(int i=n-1; i>=0; i--) { itx=sx.lower_bound(x[i]),ity=sy.lower_bound(y[i]); if(itx==sx.begin())ans+=x[i]; else itx--,ans+=x[i]-*itx; if(ity==sy.begin())ans+=y[i]; else ity--,ans+=y[i]-*ity; sx.insert(x[i]),sy.insert(y[i]); } cout<<ans<<endl; return 0; }
代码可以更短
#include<bits/stdc++.h> using namespace std; const int N=50005; int n,m,x[N],y[N]; int main() { cin>>n; for(int i=0; i<n; i++)scanf("%d%d",&x[i],&y[i]); long long ans=0; set<int> sx,sy; sx.insert(0),sy.insert(0); set<int>::iterator itx,ity; for(int i=n-1; i>=0; i--) { itx=sx.lower_bound(x[i]),ity=sy.lower_bound(y[i]); itx--,ans+=x[i]-*itx; ity--,ans+=y[i]-*ity; sx.insert(x[i]),sy.insert(y[i]); } cout<<ans<<endl; return 0; }
H. Ryuji doesn't want to study
Ryuji is not a good student, and he doesn't want to study. But there are n books he should learn, each book has its knowledge a[i]a[i].
Unfortunately, the longer he learns, the fewer he gets.
That means, if he reads books from ll to rr, he will get a[l] imes L + a[l+1] imes (L-1) + cdots + a[r-1] imes 2 + a[r]a[l]×L+a[l+1]×(L−1)+⋯+a[r−1]×2+a[r](LL is the length of [ ll, rr ] that equals to r - l + 1r−l+1).
Now Ryuji has qq questions, you should answer him:
11. If the question type is 11, you should answer how much knowledge he will get after he reads books [ ll, rr ].
22. If the question type is 22, Ryuji will change the ith book's knowledge to a new value.
Input
First line contains two integers nn and qq (nn, q le 100000q≤100000).
The next line contains n integers represent a[i]( a[i] le 1e9)a[i](a[i]≤1e9) .
Then in next qq line each line contains three integers aa, bb, cc, if a = 1a=1, it means question type is 11, and bb, cc represents [ ll, rr ]. if a = 2a=2 , it means question type is 22 , and bb, cc means Ryuji changes the bth book' knowledge to cc
Output
For each question, output one line with one integer represent the answer.
样例输入
5 3 1 2 3 4 5 1 1 3 2 5 0 1 4 5
样例输出
10 8
题目来源
线段树裸题
#include<bits/stdc++.h> using namespace std; #define LL long long const int maxn=1e5+5; LL sum[maxn<<2],sum1[maxn<<2]; void pushup(int rt) { sum[rt]=sum[rt<<1]+sum[rt<<1|1]; sum1[rt]=sum1[rt<<1]+sum1[rt<<1|1]; } void build(int l,int r,int rt) { if(l==r) { scanf("%d",&sum[rt]); sum1[rt]=sum[rt]*l; return; } int mid=(l+r)>>1; build(l,mid,rt<<1); build(mid+1,r,rt<<1|1); pushup(rt); } void update(int L,LL C,int l,int r,int rt) { if(l==r) { sum[rt]=C; sum1[rt]=sum[rt]*l; return; } int mid=(l+r)>>1; if(L<=mid)update(L,C,l,mid,rt<<1); else update(L,C,mid+1,r,rt<<1|1); pushup(rt); } LL query(int L,int R,int l,int r,int rt) { if(L<=l&&r<=R)return sum1[rt]; int mid=(l+r)>>1; LL ans=0; if(L<=mid)ans+=query(L,R,l,mid,rt<<1); if(R>mid)ans+=query(L,R,mid+1,r,rt<<1|1); return ans; } LL query1(int L,int R,int l,int r,int rt) { if(L<=l&&r<=R)return sum[rt]; int mid=(l+r)>>1; LL ans=0; if(L<=mid)ans+=query1(L,R,l,mid,rt<<1); if(R>mid)ans+=query1(L,R,mid+1,r,rt<<1|1); return ans; } int main() { int n,q; scanf("%d%d",&n,&q); build(1,n,1); for(int i=0;i<q;i++) { int op,x,y; scanf("%d%d%d",&op,&x,&y); if(op==1) { printf("%lld ",query1(x,y,1,n,1)*(y+1)-query(x,y,1,n,1)); } else if(op==2) { update(x,1LL*y,1,n,1); } } return 0; }
I. Characters with Hash
Mur loves hash algorithm, and he sometimes encrypt another one's name, and call him with that encrypted value. For instance, he calls Kimura KMR, and calls Suzuki YJSNPI. One day he read a book about SHA-256256 , which can transit a string into just 256256 bits. Mur thought that is really cool, and he came up with a new algorithm to do the similar work. The algorithm works this way: first we choose a single letter L as the seed, and for the input(you can regard the input as a string ss, s[i]s[i] represents the iith character in the string) we calculates the value(|(int) L - s[i]|∣(int)L−s[i]∣), and write down the number(keeping leading zero. The length of each answer equals to 22because the string only contains letters and numbers). Numbers writes from left to right, finally transfer all digits into a single integer(without leading zero(ss)). For instance, if we choose 'z' as the seed, the string "oMl" becomes "1111 4545 1414".
It's easy to find out that the algorithm cannot transfer any input string into the same length. Though in despair, Mur still wants to know the length of the answer the algorithm produces. Due to the silliness of Mur, he can even not figure out this, so you are assigned with the work to calculate the answer.
Input
First line a integer TT , the number of test cases (T le 10)(T≤10).
For each test case:
First line contains a integer NN and a character zz, (N le 1000000)(N≤1000000).
Second line contains a string with length NN . Problem makes sure that all characters referred in the problem are only letters.
Output
A single number which gives the answer.
样例输入
2 3 z oMl 6 Y YJSNPI
样例输出
6 10
题目来源
签到题
#include<bits/stdc++.h> using namespace std; const int maxn=1e6+5; char s[maxn],has[2]; int out[maxn]; int main() { int n,t; scanf("%d",&t); while(t--) { scanf("%d%s%s",&n,has,s); for(int i=0;i<n;i++) { int a=abs(has[0]-s[i]); out[i]=a; } int sum=n*2; for(int i=0;i<n;i++) if(out[i]==0) sum-=2; else if(out[i]<10) { sum--; break; } else break; if(sum==0)sum=1; printf("%d ",sum); } return 0; }