1002
题面
Problem Description
MZL loves xor very much.Now he gets an array A.The length of A is n.He wants to know the xor of all (Ai+Aj)(1≤i,j≤n)
The xor of an array B is defined as B1 xor B2…xor Bn
Input
Multiple test cases, the first line contains an integer T(no more than 20), indicating the number of cases.
Each test case contains four integers:n,m,z,l
A1=0,Ai=(Ai−1∗m+z) mod l
1≤m,z,l≤5∗105,n=5∗105
Output
For every test.print the answer.
Sample Input
2
3 5 5 7
6 8 8 9
Sample Output
14
16
题意
题面有点晦涩难懂。
大概意思就是给n(10^5)个数和m,z,l,其中:
A1 = 0,
Ai = (A(i - 1) * m + z ) % l。
然后求这些数中 (Ai + Aj)的值异或起来是多少。
解析
算着算着就发现这些值其实就等于原来的每个数异或起来的值左移一位。
因为LL的问题wa了一发,原因是在算数列A的时候会超LL。
代码
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <stack>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <climits>
#include <cassert>
#define LL long long
#define lson lo, mi, rt << 1
#define rson mi + 1, hi, rt << 1 | 1
using namespace std;
const int maxn = 5e5 + 10;
const int inf = 0x3f3f3f3f;
const double eps = 1e-8;
const double pi = acos(-1.0);
const double ee = exp(1.0);
LL a[maxn];
int main()
{
#ifdef LOCAL
freopen("in.txt", "r", stdin);
#endif // LOCAL
LL n, m, z, l;
int ncase;
scanf("%d", &ncase);
while (ncase--)
{
scanf("%I64d%I64d%I64d%I64d", &n, &m, &z, &l);
a[1] = 0;
for (int i = 2; i <= n; i++)
{
a[i] = (a[i - 1] * m + z) % l;
}
LL ans = 0;
for (int i = 1; i <= n; i++)
{
ans ^= a[i];
// for (int j = 1; j <= n; j++)
// {
// ans ^= (a[i] + a[j]);
// }
}
printf("%I64d\n", ans << 1);
}
return 0;
}
1005
题面
Problem Description
MZL define F(X) as the first ionization energy of the chemical element X
Now he get two chemical elements U,V,given as their atomic number,he wants to compare F(U) and F(V)
It is guaranteed that atomic numbers belongs to the given set:{1,2,3,4,..18,35,36,53,54,85,86}
It is guaranteed the two atomic numbers is either in the same period or in the same group
It is guaranteed that x≠y
Input
There are several test cases
For each test case,there are two numbers u,v,means the atomic numbers of the two element
Output
For each test case,if F(u)>F(v),print “FIRST BIGGER”,else print”SECOND BIGGER”
Sample Input
1 2
5 3
Sample Output
SECOND BIGGER
FIRST BIGGER
题意
看完题面就想吐,问队友谁是化学大神,然后就A了。
如果不是高中的时候不喜欢化学,大概也不会来这里0-0.
代码
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <string>
#include <vector>
#include <cstdio>
#include <stack>
#include <queue>
#include <cmath>
#include <list>
#include <map>
#include <set>
#define ULL unsigned long long
#define LL long long
#define INF 0x3f3f3f3f
#define eps 1e-8
using namespace std;
int element[87] = {0,
23, 24,
15, 17, 16, 18, 20, 19, 21, 22,
7, 9, 8, 10, 12, 11, 13, 14};
int main()
{
#ifdef LOCAL
//freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
#endif // LOCAL
int a, b;
element[35] = 5;
element[36] = 6;
element[53] = 3;
element[54] = 4;
element[85] = 1;
element[86] = 2;
while(cin >> a >> b)
{
if (element[a] > element[b])
cout << "FIRST BIGGER" <<endl;
else
cout << "SECOND BIGGER" << endl;
}
return 0;
}
1007
题面
Problem Description
You have a multiple set,and now there are three kinds of operations:
1 x : add number x to set
2 : delete the minimum number (if the set is empty now,then ignore it)
3 : query the maximum number (if the set is empty now,the answer is 0)
Input
The first line contains a number N (N≤106),representing the number of operations.
Next N line ,each line contains one or two numbers,describe one operation.
The number in this set is not greater than 109.
Output
For each operation 3,output a line representing the answer.
Sample Input
6
1 2
1 3
3
1 3
1 4
3
Sample Output
3
4
题意
按照题目当中的几个询问去做就好了。
解析
用multiset。
记得第一次接触multiset的时候是和韬哥一起打cf,然后一道很水的题目做不出来,韬哥用multiset搞出来的。
题意已经记不清了,反正赛后一看题解当时就呵呵了。
代码
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <string>
#include <vector>
#include <cstdio>
#include <stack>
#include <queue>
#include <cmath>
#include <list>
#include <map>
#include <set>
#define ULL unsigned long long
#define LL long long
#define INF 0x3f3f3f3f
#define eps 1e-8
using namespace std;
int main()
{
#ifdef LOCAL
//freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
#endif // LOCAL
int n;
int a, b;
while(scanf("%d", &n) != EOF)
{
multiset<int> s;
for (int i = 0; i < n; ++i)
{
scanf("%d", &a);
if (a == 3)
{
if(s.empty())
printf("0\n");
else
{
set<int>::iterator it = s.end();
it--;
printf("%d\n", *it);
}
}
else if (a == 1)
{
scanf("%d", &b);
s.insert(b);
}
else
{
if (!s.empty())
s.erase(s.begin());
}
}
}
return 0;
}
1009
题面
Problem Description
As is known to all, MZL is an extraordinarily lovely girl. One day, MZL was playing with her favorite data structure, strings.
MZL is really like Fibonacci Sequence, so she defines Fibonacci Strings in the similar way. The definition of Fibonacci Strings is given below.
1) fib1=b
2) fib2=a
3) fibi=fibi−1fibi−2, i>2
For instance, fib3=ab, fib4=aba, fib5=abaab.
Assume that a string s whose length is n is s1s2s3…sn. Then sisi+1si+2si+3…sj is called as a substring of s, which is written as s[i:j].
Assume that i < n . If s[1:i]=s[n−i+1:n], then s[1:i] is called as a Border of s. In Borders of s, the longest Border is called as s’ LBorder. Moreover, s[1:i] ’ s LBorder is called as LBorderi.
Now you are given 2 numbers n and m. MZL wonders what LBorderm of fibn is. For the number can be very big, you should just output the number modulo 258280327(=2×317+1).
Note that 1≤T≤100, 1≤n≤103, 1≤m≤|fibn|.
Input
The first line of the input is a number T, which means the number of test cases.
Then for the following T lines, each has two positive integers n and m, whose meanings are described in the description.
Output
The output consists of T lines. Each has one number, meaning fibn’s LBorderm modulo 258280327(=2×317+1).
Sample Input
2
4 3
5 5
Sample Output
1
2
题意
有一个斐波那契串:
fib1 = b, fib2 = a,
fib3 = ab, fib4 = aba, fib5 = abaab,
fib6 = abaababa…
然后给n(1000)和m(……)。
解析
m是从1到fibn的长度。当时就懵逼了,卧槽,fib1000的长度简直突破天际,如果是一个O(fib1000)的算法我的计算机可以玩300年。
完全没有往高精度大数方面想。
然后就开始找规律打表。最终GG。
这题最终的规律是找到第一个i使得m+1 < |fibi|,然后输出fib(i- 2)的值就行了。
然后喜获一大数模板- -。
代码
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <stack>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <climits>
#include <cassert>
#define LL long long
#define lson lo, mi, rt << 1
#define rson mi + 1, hi, rt << 1 | 1
using namespace std;
const int maxn = 1000 + 10;
const int inf = 0x3f3f3f3f;
const double eps = 1e-8;
const double pi = acos(-1.0);
const double ee = exp(1.0);
const int mod = 258280327;
struct huge
{
#define N_huge 850
#define base 100000000
static char s[N_huge*10];
typedef long long value;
value a[N_huge];
int len;
void clear()
{
len=1;
a[len]=0;
}
huge()
{
clear();
}
huge(value x)
{
*this=x;
}
huge operator =(huge b)
{
len=b.len;
for (int i=1; i<=len; ++i)a[i]=b.a[i];
return *this;
}
huge operator +(huge b)
{
int L=len>b.len?len:b.len;
huge tmp;
for (int i=1; i<=L+1; ++i)tmp.a[i]=0;
for (int i=1; i<=L; ++i)
{
if (i>len)tmp.a[i]+=b.a[i];
else if (i>b.len)tmp.a[i]+=a[i];
else
{
tmp.a[i]+=a[i]+b.a[i];
if (tmp.a[i]>=base)
{
tmp.a[i]-=base;
++tmp.a[i+1];
}
}
}
if (tmp.a[L+1])tmp.len=L+1;
else tmp.len=L;
return tmp;
}
huge operator -(huge b)
{
int L=len>b.len?len:b.len;
huge tmp;
for (int i=1; i<=L+1; ++i)tmp.a[i]=0;
for (int i=1; i<=L; ++i)
{
if (i>b.len)b.a[i]=0;
tmp.a[i]+=a[i]-b.a[i];
if (tmp.a[i]<0)
{
tmp.a[i]+=base;
--tmp.a[i+1];
}
}
while (L>1&&!tmp.a[L])--L;
tmp.len=L;
return tmp;
}
huge operator *(huge b)
{
int L=len+b.len;
huge tmp;
for (int i=1; i<=L; ++i)tmp.a[i]=0;
for (int i=1; i<=len; ++i)
for (int j=1; j<=b.len; ++j)
{
tmp.a[i+j-1]+=a[i]*b.a[j];
if (tmp.a[i+j-1]>=base)
{
tmp.a[i+j]+=tmp.a[i+j-1]/base;
tmp.a[i+j-1]%=base;
}
}
tmp.len=len+b.len;
while (tmp.len>1&&!tmp.a[tmp.len])--tmp.len;
return tmp;
}
pair<huge,huge> divide(huge a,huge b)
{
int L=a.len;
huge c,d;
for (int i=L; i; --i)
{
c.a[i]=0;
d=d*base;
d.a[1]=a.a[i];
//while (d>=b){d-=b;++c.a[i];}
int l=0,r=base-1,mid;
while (l<r)
{
mid=(l+r+1)>>1;
if (b*mid<=d)l=mid;
else r=mid-1;
}
c.a[i]=l;
d-=b*l;
}
while (L>1&&!c.a[L])--L;
c.len=L;
return make_pair(c,d);
}
huge operator /(value x)
{
value d=0;
huge tmp;
for (int i=len; i; --i)
{
d=d*base+a[i];
tmp.a[i]=d/x;
d%=x;
}
tmp.len=len;
while (tmp.len>1&&!tmp.a[tmp.len])--tmp.len;
return tmp;
}
value operator %(value x)
{
value d=0;
for (int i=len; i; --i)d=(d*base+a[i])%x;
return d;
}
huge operator /(huge b)
{
return divide(*this,b).first;
}
huge operator %(huge b)
{
return divide(*this,b).second;
}
huge &operator +=(huge b)
{
*this=*this+b;
return *this;
}
huge &operator -=(huge b)
{
*this=*this-b;
return *this;
}
huge &operator *=(huge b)
{
*this=*this*b;
return *this;
}
huge &operator ++()
{
huge T;
T=1;
*this=*this+T;
return *this;
}
huge &operator --()
{
huge T;
T=1;
*this=*this-T;
return *this;
}
huge operator ++(int)
{
huge T,tmp=*this;
T=1;
*this=*this+T;
return tmp;
}
huge operator --(int)
{
huge T,tmp=*this;
T=1;
*this=*this-T;
return tmp;
}
huge operator +(value x)
{
huge T;
T=x;
return *this+T;
}
huge operator -(value x)
{
huge T;
T=x;
return *this-T;
}
huge operator *(value x)
{
huge T;
T=x;
return *this*T;
}
//huge operator /(value x){huge T;T=x;return *this/T;}
//huge operator %(value x){huge T;T=x;return *this%T;}
huge operator *=(value x)
{
*this=*this*x;
return *this;
}
huge operator +=(value x)
{
*this=*this+x;
return *this;
}
huge operator -=(value x)
{
*this=*this-x;
return *this;
}
huge operator /=(value x)
{
*this=*this/x;
return *this;
}
huge operator %=(value x)
{
*this=*this%x;
return *this;
}
bool operator ==(value x)
{
huge T;
T=x;
return *this==T;
}
bool operator !=(value x)
{
huge T;
T=x;
return *this!=T;
}
bool operator <=(value x)
{
huge T;
T=x;
return *this<=T;
}
bool operator >=(value x)
{
huge T;
T=x;
return *this>=T;
}
bool operator <(value x)
{
huge T;
T=x;
return *this<T;
}
bool operator >(value x)
{
huge T;
T=x;
return *this>T;
}
huge operator =(value x)
{
len=0;
while (x)a[++len]=x%base,x/=base;
if (!len)a[++len]=0;
return *this;
}
bool operator <(huge b)
{
if (len<b.len)return 1;
if (len>b.len)return 0;
for (int i=len; i; --i)
{
if (a[i]<b.a[i])return 1;
if (a[i]>b.a[i])return 0;
}
return 0;
}
bool operator ==(huge b)
{
if (len!=b.len)return 0;
for (int i=len; i; --i)
if (a[i]!=b.a[i])return 0;
return 1;
}
bool operator !=(huge b)
{
return !(*this==b);
}
bool operator >(huge b)
{
return !(*this<b||*this==b);
}
bool operator <=(huge b)
{
return (*this<b)||(*this==b);
}
bool operator >=(huge b)
{
return (*this>b)||(*this==b);
}
huge str(char s[])
{
int l=strlen(s);
value x=0,y=1;
len=0;
for (int i=l-1; i>=0; --i)
{
x=x+(s[i]-'0')*y;
y*=10;
if (y==base)a[++len]=x,x=0,y=1;
}
if (!len||x)a[++len]=x;
}
void read()
{
scanf("%s",s);
this->str(s);
}
void print()
{
printf("%d",(int)a[len]);
for (int i=len-1; i; --i)
{
for (int j=base/10; j>=10; j/=10)
{
if (a[i]<j)printf("0");
else break;
}
printf("%d",(int)a[i]);
}
printf("\n");
}
};
char huge::s[N_huge*10];
huge fib[maxn];
void init()
{
fib[1] = 1;
fib[2] = 1;
for (int i = 3; i < maxn; i++)
{
fib[i] = fib[i - 1] + fib[i - 2];
}
}
int main()
{
#ifdef LOCAL
freopen("in.txt", "r", stdin);
#endif // LOCAL
init();
int ncase;
scanf("%d", &ncase);
while (ncase--)
{
int n;
scanf("%d", &n);
huge m;
m.read();
if (m == 1 || m == 2)
{
printf("0\n");
continue;
}
int i;
for (i = 2; i < n + 2; i++)
{
if (m + 1 < fib[i])
break;
}
m = m - fib[i - 2];
m %= mod;
m.print();
}
return 0;
}