/*
* @Author: foreignbill
* @Date: 2018-09-01 11:52:42
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n;
int main () {
int T;
for(scanf("%d",&T);T--;) {
scanf("%lld",&n);
printf("%lldn",n-1);
}
return 0;
}
B
/*
* @Author: foreignbill
* @Date: 2018-09-01 14:56:08
*/
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 555;
typedef long long ll;
short mp[maxn][105];
vector<pair<int, int>> Color[3];
int m, n, k, x, y;
vector<int> base[maxn];
int bottom[maxn];
void init1() {
for (int i = 1; i <= n; i++) {
base[i].clear();
}
}
void init2() {
for (int i = 1; i <= m; i++) base[i].clear();
for (int i = 1; i <= m; i++)
if (bottom[i]) base[bottom[i]].push_back(i);
}
ll calc(int col) {
memset(bottom, 0, sizeof(bottom));
init1();
ll ans = 0;
for (auto now : Color[col]) {
int nextx = now.first, nexty = now.second;
init2();
int zqx = 1, zqy = m;
bool flag = false;
for (int i = nextx; i >= 1; i--) {
for (vector<int>::iterator it = base[i].begin(); it != base[i].end(); it++) {
int too = *it;
if (too < nexty) zqx = max(zqx, too + 1);
else if (too > nexty) zqy = min (zqy, too - 1);
else {
flag = true;
break;
}
}
if (flag) break;
ans += 1LL*(n - nextx + 1) *1LL* (nexty - zqx + 1) * 1LL *(zqy - nexty + 1);
}
bottom[nexty] = nextx;
}
return ans;
}
int main() {
int t; cin >> t;
for(int cas = 1; cas <= t; cas ++ ) {
for (int i = 0; i < 2; i++) {
Color[i].clear();
}
scanf("%d%d%d", &n, &m, &k);
int id = 1;
memset(mp,0,sizeof mp);
for(int i = 1; i <= k; i++) {
scanf("%d%d", &x, &y);
mp[x][y] = 1;
}
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= m; j++) {
if(mp[i][j] == 0) mp[i][j] = 2;
}
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
if(mp[i][j] == 2) continue;
Color[mp[i][j]].push_back(make_pair(i, j));
}
}
for (int i = 0; i < 2; i++) {
if (!Color[i].empty()) {
sort(Color[i].begin(), Color[i].end());
}
}
ll num = 1ll * n * (n + 1) * m * (m + 1) / 4;
printf("Case #%d: %lldn",cas, num - calc(1));
}
return 0;
}
C
/*
* @Author: foreignbill
* @Date: 2018-09-01 15:29:19
*/
#include <bits/stdc++.h>
using namespace std;
const int maxn = 205;
const int maxm = 20005;
int a[15][maxn],n,m;
int res[maxn];
int rk[15]={0,3,4,5,6,7,8,9,10,11,12,13,1,2};//13
int rv[15]={0,12,13,1,2,3,4,5,6,7,8,9,10,11};
queue<int> Q;
inline int find(int id,int lst) {
if(lst == 0) {
for(int i=1;i<=13;i++)
if(a[rk[i]][id] > 0) return rk[i];
} else {
if(lst == 2) return -1;
if(a[rk[rv[lst%13+1]]][id] > 0) return rk[rv[lst%13+1]];
if(a[2][id] > 0) return 2;
}
return -1;
}
int main () {
freopen("input.txt","r",stdin);
int Cas=1;
int T;for(scanf("%d",&T);T--;) {
scanf("%d%d",&n,&m);
while(!Q.empty()) Q.pop();
for(int i=1;i<=m;i++) {
int x;scanf("%d",&x);
Q.push(x);
}
memset(a,0,sizeof a);
for(int i=0;i<n;i++) {
for(int j=0;j<5;j++) {
if(Q.size() == 0) break;
a[Q.front()][i]++;
Q.pop();
}
}
int lst = 0;
int now = 0;
int nowp = 0;
int cnt = 0;
while(1) {
if(cnt == n-1) {
cnt = 0;
for(int i=0;i<n;i++) {
if(Q.size() == 0) break;
a[Q.front()][(now+i)%n]++;
Q.pop();
}
lst = 0;
continue;
}
int nowp = find(now,lst);
if(nowp == -1) cnt++;
else {
cnt = 0;
a[nowp][now]--;
lst = nowp;
int chk=0;
for(int i=1;i<=13;i++)
chk += a[i][now];
if(!chk) break;
}
now = (now + 1) % n;
}
printf("Case #%d:n", Cas++);
for(int i=0;i<n;i++) {
res[i] = 0;
for(int j=1;j<=13;j++) {
res[i] += a[j][i] * j;
}
if(i==now || res[i]==0) printf("Winnern");
else printf("%dn",res[i]);
}
}
return 0;
}
E
/*
* @Author: foreignbill
* @Date: 2018-09-01 14:36:57
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1<<20;
ll dp[maxn];
int t[maxn];
int n;
struct node {
int a,b,tp;
void read() {
int top, v;
scanf("%d%d%d",&a,&b,&top);
tp = 0;
for(int i=1;i<=top;i++) {
scanf("%d",&v);
tp = tp + (1<<(v-1));
}
}
}info[25];
int main () {
scanf("%d",&n);
memset(dp,0,sizeof dp);
t[0]=1;
for(int i=0;i<n;i++)
info[i].read();
for(int i=0;i<(1<<n);i++) {
for(int j=0;j<n;j++) {
if((i&info[j].tp) == info[j].tp) {
if((i>>j)&1) continue;
if(dp[i] + 1ll * t[i] * info[j].a + info[j].b > dp[i | (1<<j)]) {
dp[i | (1<<j)] = dp[i] + 1ll * t[i] * info[j].a + info[j].b;
t[i | (1<<j)] = t[i] + 1;
}
}
}
}
ll res = 0;
for(int i=0;i<(1<<n);i++)
res = max(res,dp[i]);
cout << res << endl;
return 0;
}
G
//
// Author: foreignbill
// Time: 2018-09-02
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 555;
const int inf = INT_MAX;
typedef long long ll;
typedef pair<int,int> pii;
int Tr[maxn << 2];
int a[maxn];
int n, m;
int ra[maxn],rb[maxn];
inline void build(int id,int l,int r) {
if(l == r) {
Tr[id] = a[l];
return;
}
int mid = (l + r) >> 1;
build(id<<1,l,mid);
build(id<<1|1,mid+1,r);
Tr[id] = min(Tr[id<<1],Tr[id<<1|1]);
}
inline pii query(int id,int l,int r,int x) {
if(l == r) {
return make_pair(l,Tr[id]);
}
int mid = (l + r) >> 1;
if(Tr[id<<1] <= x) return query(id<<1,l,mid,x);
if(Tr[id<<1|1] <= x) return query(id<<1|1,mid+1,r,x);
return make_pair(-1,inf);
}
inline void change(int id,int l,int r,int pos,int x) {
if(l == r) {
Tr[id] = x;
return;
}
int mid = (l + r) >> 1;
if(mid >= pos) change(id<<1,l,mid,pos,x);
else change(id<<1|1,mid+1,r,pos,x);
Tr[id] = min(Tr[id<<1],Tr[id<<1|1]);
}
int main() {
scanf("%d%d",&n, &m);
for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
build(1,1,n);
int lst = 0;
int already = 0;
for(int i=1;i<=100000;i++) {
lst += m;
while(true) {
// cout << "#" << already << " " << lst << endl;
pii tmp = query(1,1,n,lst);
// cout << tmp.first << " " << tmp.second << endl;
if(tmp.second > lst) break;
lst -= tmp.second;
already++;
change(1,1,n,tmp.first,inf);
}
ra[i] = already;
rb[i] = lst;
}
int q,_;
scanf("%d",&q);
while(q--) {
scanf("%d",&_);
printf("%d %dn",ra[_],rb[_]);
}
return 0;
}
I
/*
* @Author: foreignbill
* @Date: 2018-09-01 14:14:59
*/
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
const int maxn = 4e6 + 555;
ull P = 1313131;
ull sqr[maxn],has[maxn],V[maxn];
ll Pow[maxn],line[maxn];
int ans = 0;
const int MOD = 2000007;
const int mod = 1e9 + 7;
int Laxt[maxn],Next[maxn],cnt=0;
ll res = 0;
bool insert(ull now) {
int u = now % MOD;
for(int i=Laxt[u];i;i=Next[i]){
if(V[i]==now) return true;
}
Next[++cnt]=Laxt[u];
Laxt[u]=cnt;
V[cnt]=now;
return false;
}
void Hash(int x,int y) {
ull now = has[y] - has[x-1] * sqr[y-x+1];
if(!insert(now)) {
res += (line[y] - line[x-1] * Pow[y-x+1] % mod) % mod;
//cout << (line[y] - line[x-1] * Pow[y-x+1] % mod) % mod << endl;
res %= mod;
ans++;
}
}
char st[maxn];
int r[maxn];
void manacher () {
// this is a template
res = 0;
int R=0,Mid=0,Len;
scanf("%s",st+1);
Len=strlen(st+1);
sqr[0]=1;
for(int i=1;i<=Len;i++){
sqr[i]=sqr[i-1]*P;
has[i]=has[i-1]*P+st[i];
}
Pow[0]=1;
line[0]=0;
for(int i=1;i<=Len;i++) {
Pow[i]=Pow[i-1]*10%mod;
line[i]=line[i-1]*10+(st[i]-'0');
line[i]%=mod;
}
for(int i=1;i<=Len;++i) {
Hash(i,i);
if(R>i) r[i]=min(r[2*Mid-i],R-i);
while(i+r[i]+1<=Len&&st[i+r[i]+1]==st[i-r[i]-1]){
Hash(i-r[i]-1,i+r[i]+1);
r[i]++;
}
if(i+r[i]>R) {
R=i+r[i];
Mid=i;
}
}
cnt=0;Mid=0;R=0;
memset(Laxt,0,sizeof(Laxt));
memset(r,0,sizeof(r));
for(int i=2;i<=Len;++i) {
if(R>i) r[i]=min(r[2*Mid-i],R-i+1);
while(i+r[i]<=Len&&st[i+r[i]]==st[i-r[i]-1]) {
Hash(i-r[i]-1,i+r[i]);
++r[i];
}
if(i+r[i]-1>R) {
R=i+r[i]-1;
Mid=i;
}
}
printf("%lldn",(res+mod)%mod);
}
int main() {
manacher();
return 0;
}
J
/*
* @Author: foreignbill
* @Date: 2018-09-01 12:08:07
*/
#pragma GCC optimize(3,"Ofast","inline")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2e7 + 555;
const int N = 2e7+5;
bool p[maxn];
int prime[maxn],top;
ll cnt[maxn];
void init() {
register int i, j;
memset(p, 0, sizeof p);
top = 0;
cnt[1] = 1;
for (i = 2; i <= N; ++i) {
if (!p[i]) {
prime[++top] = i;
cnt[i] = 2;
}
for (j = 1; j <= top; ++j) {
if (1ll * i * prime[j] > N)
break;
p[i * prime[j]] = 1;
if (i % prime[j] == 0) {
if(i%(prime[j]*prime[j]) != 0) cnt[i * prime[j]] = cnt[i / prime[j]];
break;
}
cnt[i*prime[j]] = cnt[i] << 1;
}
}
// cout << cnt[36] << endl;
for(int i=2;i<=N;i++) {
assert(cnt[i] >= 0);
cnt[i] += cnt[i-1];
}
}
int main () {
init();
int T;for(scanf("%d",&T);T--;) {
int n;scanf("%d",&n);
printf("%lldn",cnt[n]);
}
return 0;
}
L
/*
* @Author: foreignbill
* @Date: 2018-09-01 12:21:08
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 555;
const ll inf = 1e16;
vector<pair<int,int> > e[maxn];
ll dist[11][maxn];
bool vis[maxn];
int n, m, k, u, v, w;
namespace IO {
const int MT = 40 * 1024 * 1024; /// 10MB 请注意输入数据的大小!!!
char IO_BUF[MT];
int IO_PTR, IO_SZ;
/// 要记得把这一行添加到main 函数第一行!!!
void begin() {
IO_PTR = 0;
IO_SZ = fread (IO_BUF, 1, MT, stdin);
}
template<typename T>
inline bool scan_d (T & t) {
while (IO_PTR < IO_SZ && IO_BUF[IO_PTR] != '-' && (IO_BUF[IO_PTR] < '0' || IO_BUF[IO_PTR] > '9'))
IO_PTR ++;
if (IO_PTR >= IO_SZ) return false;
bool sgn = false;
if (IO_BUF[IO_PTR] == '-') sgn = true, IO_PTR ++;
for (t = 0; IO_PTR < IO_SZ && '0' <= IO_BUF[IO_PTR] && IO_BUF[IO_PTR] <= '9'; IO_PTR ++)
t = t * 10 + IO_BUF[IO_PTR] - '0';
if (sgn) t = -t;
return true;
}
inline bool scan_s (char s[]) {
while (IO_PTR < IO_SZ && (IO_BUF[IO_PTR] == ' ' || IO_BUF[IO_PTR] == 'n') ) IO_PTR ++;
if (IO_PTR >= IO_SZ) return false;
int len = 0;
while (IO_PTR < IO_SZ && IO_BUF[IO_PTR] != ' ' && IO_BUF[IO_PTR] != 'n')
s[len ++] = IO_BUF[IO_PTR], IO_PTR ++;
s[len] = '
近期评论