打OI这么多年,突然想起做的第一道题:Hello,word! 有感而发,写了一段小小的程序:
#include<bits/stdc++.h>
using namespace std;
#define set(x) Set(x)
#define REP(i,j,k) for (int i=(j),_end_=(k);i<=_end_;++i)
#define DREP(i,j,k) for (int i=(j),_start_=(k);i>=_start_;--i)
#define mp make_pair
#define x first
#define y second
#define MAXNG 10010
#define MAXM 500010
#define MAX 2147483647
#define N 100000
template<typename T> inline bool chkmin(T &a,const T &b){ return a > b ? a = b, 1 : 0; }
typedef pair<int,int> node;
const int dmax = 1010, oo = 0x3f3f3f3f;
int a[dmax][dmax],ans,d[dmax], e[dmax];
priority_queue <node> q;
struct Edge {
int v,w;
};
int c = 1;
int head[MAXNG], path[MAXNG];
vector<Edge> edge[405*405];
int m;
int dis[405*405];
bool vis[405*405];
int v[110], w[110];
int h[110], ne[110], idx;
int f[110][110];
int sz[N], rev[N], tag[N], sum[N], ch[N][2], fa[N], val[N],n, rt;
int xa[10], st1[10][17];
const int MAXN = 1e8 + 10;
int ya[MAXN];
struct nod {
int next, to, w;
}qa[MAXM << 1];
int x[2][2] = {{0, 1},{1, 1}};
int aST[10], st[10][17];
struct cmp {
bool operator()(int a,int b) {
return dis[a]>dis[b];
}
};
int Dijkstra(int start,int end){
priority_queue<int,vector<int>,cmp> dijQue;
memset(dis,-1,sizeof(dis));
memset(vis,0,sizeof(vis));
dijQue.push(start);
dis[start]=0;
while(!dijQue.empty()) {
int u=dijQue.top();
dijQue.pop();
vis[u]=0;
if(u==end)
break;
for(int i=0; i<edge[u].size(); i++) {
int v=edge[u][i].v;
if(dis[v]==-1 || dis[v]>dis[u]+edge[u][i].w) {
dis[v]=dis[u]+edge[u][i].w;
if(!vis[v]) {
vis[v]=true;
dijQue.push(v);
}
}
}
}
return dis[end];
}
int add_1(int a,int b){
Edge Qpush;
Qpush.v=1;
Qpush.w=a;
edge[0].push_back(Qpush);
Qpush.v=2;
Qpush.w=b;
edge[1].push_back(Qpush);
return Dijkstra(0,2);
}
void push_up(int x){
sz[x] = sz[ch[x][0]] + sz[ch[x][1]] + 1;
sum[x] = sum[ch[x][1]] + sum[ch[x][0]] + val[x];
}
void push_down(int x){
if(rev[x]){
swap(ch[x][0], ch[x][1]);
if(ch[x][1]) rev[ch[x][1]] ^= 1;
if(ch[x][0]) rev[ch[x][0]] ^= 1;
rev[x] = 0;
}
if(tag[x]){
if(ch[x][1]) tag[ch[x][1]] += tag[x], sum[ch[x][1]] += tag[x];
if(ch[x][0]) tag[ch[x][0]] += tag[x], sum[ch[x][0]] += tag[x];
tag[x] = 0;
}
}
void rotate(int x, int &k){
int y = fa[x], z = fa[fa[x]];
int kind = ch[y][1] == x;
if(y == k) k = x;
else ch[z][ch[z][1]==y] = x;
fa[x] = z; fa[y] = x; fa[ch[x][!kind]] = y;
ch[y][kind] = ch[x][!kind]; ch[x][!kind] = y;
push_up(y); push_up(x);
}
void splay(int x, int &k){
while(x != k){
int y = fa[x], z = fa[fa[x]];
if(y != k) if(ch[y][1] == x ^ ch[z][1] == y) rotate(x, k);
else rotate(y, k);
rotate(x, k);
}
}
int kth(int x, int k){
push_down(x);
int r = sz[ch[x][0]]+1;
if(k == r) return x;
if(k < r) return kth(ch[x][0], k);
else return kth(ch[x][1], k-r);
}
void split(int l, int r){
int x = kth(rt, l), y = kth(rt, r+2);
splay(x, rt); splay(y, ch[rt][1]);
}
void rever(int l, int r){
split(l, r);
rev[ch[ch[rt][1]][0]] ^= 1;
}
void add_2(int l, int r, int v){
split(l, r);
tag[ch[ch[rt][1]][0]] += v;
val[ch[ch[rt][1]][0]] += v;
push_up(ch[ch[rt][1]][0]);
}
int build(int l, int r, int f){
if(l > r) return 0;
if(l == r){
fa[l] = f;
sz[l] = 1;
return l;
}
int mid = l + r >> 1;
ch[mid][0] = build(l, mid-1, mid);
ch[mid][1] = build(mid+1, r, mid);
fa[mid] = f;
push_up(mid);
return mid;
}
int asksum(int l, int r){
split(l, r);
return sum[ch[ch[rt][1]][0]];
}
void print_1(int str,int cnst){
cout<< char(add_1(str,cnst));
return;
}
void print_2(int str,int cnst){
n = 2;
rt = build(1, n+2, 0);
add_2(1, 1, str);
add_2(2, 2, cnst);
rever(1, n);
cout<<char(asksum(1, n));
}
int add_3(int a,int b){
int fu=1,f=1,c=0;
if(a<0&&b>0)
fu=2;
if(a>0&&b<0)
fu=3;
if(a<0&&b<0)
f=-1;
if(a==0)
return b;
if(b==0)
return a;
a=abs(a);
b=abs(b);
if(a>b&&fu==3)
f=1;
if(b>a&&fu==3)
f=-1;
if(b>a&&fu==2)
f=1;
if(b<a&&fu==2)
f=-1;
if(fu==1)
c=a+b;
if(fu>1)
c=max(a,b)-min(a,b);
c*=f;
return c;
}
void print_3(int str,int cnst){
cout<<char(add_3(str,cnst));
return;
}
int lowbit(int a){
return a&(-a);
}
int add_4(int x,int y){
int n=2,m=1;
int ans[m+1];
int a[n+1],c[n+1],s[n+1];
int o=0;
memset(c,0,sizeof(c));
s[0]=0;
a[1] = x;
s[1]=s[0]+a[1];
c[1]=s[1]-s[1-lowbit(1)];
a[2] = y;
s[2]=s[1]+a[2];
c[2]=s[2]-s[2-lowbit(2)];
for(int i=1;i<=m;i++){
int q=2;
int x=1,y=2;
int s1=0,s2=0,p=x-1;
while(p>0){
s1+=c[p];
p-=lowbit(p);
}
p=y;
while(p>0){
s2+=c[p];
p-=lowbit(p);
}
o++;
ans[o]=s2-s1;
}
int anss;
if(o == 1){
anss = ans[1];
}
else if(o == 2){
anss += ans[2]*10 + ans[1];
}
else{
anss += ans[3]*100 + ans[2]*10 + ans[1];
}
return anss;
}
void print_4(int str,int cnst){
cout<<char(add_4(str,cnst));
return;
}
inline bool operator >(node a,node b){
return a.y>b.y;
}
bool p[dmax];
void Set(int x){
p[x] = 1;
}
void unset(int x){
p[x] = 0;
}
bool check(int x){
return x != 1 && x != n && !p[x] && e[x] > 0;
}
void preflow(){
e[1] = oo;
d[1] = n - 1;
q.push(mp(1, n - 1));
set(1);
while (!q.empty()) {
bool flag = 1;
int k = q.top().x;
q.pop(), unset(k);
DREP(i, n, 1)
if ((d[k] == d[i] + 1 || k == 1) && a[k][i] > 0){
flag = 0;
int t = min(a[k][i], e[k]);
e[k] -= t;
a[k][i] -= t;
e[i] += t;
a[i][k] += t;
if (check(i)) {
q.push(mp(i, d[i]));
set(i);
}
if (e[k] == 0) break;
}
if (flag) {
d[k] = oo;
REP(i, 1, n)
if (a[k][i] > 0) chkmin(d[k], d[i] + 1);
}
if (check(k)) {
q.push(mp(k, d[k]));
set(k);
}
}
ans = e[n];
}
void print_5(int str,int cnst) {
n = 2;
m = 2;
a[1][2] += str + cnst;
preflow();
cout<<char(ans);
return;
}
void ST_work1() {
for (int i = 1; i <= n; i++) st1[i][0] = xa[i];
int t = log(n) / log(2) + 1;
for (int j = 1; j < t; j++) {
for (int i = 1; i <= n - (1 << j) + 1; i++)
st1[i][j] = max(st1[i][j - 1], st1[i + (1 << (j - 1))][j - 1]);
}
}
int ST_query1(int l, int r) {
int k = log(r - l + 1) / log(2);
return max(st1[l][k], st1[r - (1 << k) + 1][k]);
}
void ST_work2() {
for (int i = 1; i <= n; i++) st1[i][0] = xa[i];
int t = log(n) / log(2) + 1;
for (int j = 1; j < t; j++) {
for (int i = 1; i <= n - (1 << j) + 1; i++)
st1[i][j] = min(st1[i][j - 1], st1[i + (1 << (j - 1))][j - 1]);
}
}
int ST_query2(int l, int r) {
int k = log(r - l + 1) / log(2);
return min(st1[l][k], st1[r - (1 << k) + 1][k]);
}
int add_6(int a,int b) {
n = 2;
xa[1] = a;
xa[2] = b;
ST_work1();
int ans1 = ST_query1(1, 2);
ST_work2();
int ans2 = ST_query2(1, 2);
return (ans1 + ans2);
}
void print_6(int str,int cnst){
cout<<char(add_6(str,cnst));
return;
}
int qmi(int m, int k, int p) {
int res = 1 % p, t = m;
while (k) {
if (k & 1) res = res * t % p;
t = t * t % p;
k >>= 1;
}
return res;
}
void print_7(int str,int cnst){
cout<<char(qmi(str, 1, 100000010) + qmi(cnst, 1, 100000010));
return;
}
int check() {
for (int i = 1;i < n; i++)
if(ya[i] > ya[i + 1])
return 0;
return 1;
}
void print_8(int str,int cnst) {
n = 2;
ya[1] = str;
ya[2] = cnst;
while (1) {
random_shuffle(ya + 1, ya + 1 + n);
if(check())
break;
}
int ans = 0;
for (int i = 1;i <= n; i++)
ans += ya[i];
cout<<char(ans);
return;
}
inline int relax (int u, int v, int w) {
if (path[v] > path[u] + w) {
path[v] = path[u] + w;
return 1;
}
return 0;
}
inline void add(int u, int v, int w) {
qa[c].to = v;
qa[c].w = w;
qa[c].next = head[u];
head[u] = c++;
}
void spfa() {
int u, v, num = 0;
long long x = 0;
list<int> q;
for (int i = 1;i <= n; i++){path[i] = MAX; vis[i] = 0;}
path[1] = 0;
vis[1] = 1;
q.push_back(1);
num++;
while (!q.empty()) {
u = q.front();
q.pop_front();
num--; x -= path[u];
while (num && path[u] > x / num){
q.push_back(u);
u = q.front();
q.pop_front();
}
vis[u] = 0;
for (int i = head[u]; i ; i = qa[i].next) {
v = qa[i].to;
if (relax(u, v, qa[i].w) && !vis[v]) {
vis[v] = 1;
if(!q.empty() && path[v] < path[q.front()]) q.push_front(v);
else q.push_back(v);
num++; x += path[v];
}
}
}
}
void print_9(int str,int cnst) {
n = 3;
m = 2;
add(1, 2, str);
add(2, 3, cnst);
spfa();
cout<<char(path[n]);
return;
}
void mo(int f[]) {
int ans[2] = {0};
for(int i = 0; i < 2; i++)
for(int j = 0; j < 2; j++) ans[i] += f[j] * x[i][j];
for(int i = 0; i < 2; i++)
f[i] = ans[i];
}
void print_10(int cnt,int cnst) {
int f[3] = {cnt,cnst};
mo(f);
cout << char(f[1]);
return;
}
void print_11(int str,int cnst) {
int s = 0 ,s1 = 0, i= 0, na= 0, nb= 0,a,b;
a = str;
b = cnst;
if (a <= 0) na = 1, a = abs(a);
while(a) {
if ((a & 1) != 0)
s += pow(2, (a & 1) * i);
a >>= 1; i++;
}
i = 0;
if (na == 1)
s = abs(s);
if (b <= 0)
nb = 1, b = abs(b);
while(b) {
if ((b & 1) != 0)
s1 += pow(2, (b & 1) * i);
b >>= 1; i++;
}
if (nb == 1)
s1 = abs(s1);
cout<<char(s + s1);
return;
}
void add(int a, int b) {
e[idx] = b, ne[idx] = h[a], h[a] = idx++;
}
void dfs(int u) {
for (int i = h[u]; ~i; i = ne[i]) {
int son = e[i];
dfs(e[i]);
for (int j = m - v[u]; j >= 0; j -- )
for (int k = 0; k <= j; k ++ )
f[u][j] = max(f[u][j], f[u][j - k] + f[son][k]);
}
for (int i = m; i >= v[u]; i -- )
f[u][i] = f[u][i - v[u]] + w[u];
for (int i = 0; i < v[u]; i ++ )
f[u][i] = 0;
}
void print_12(int str,int cnst) {
n = m = 2;
memset(h, -1, sizeof h);
int root;
int p;
v[1] = 1;
w[1] = str;
p = -1;
root = 1;
v[2] = 1;
w[2] = cnst;
p = 1;
add(p, 2);
dfs(root);
cout<<char(f[root][m]);
return;
}
signed main(){
int str[12] = {7,36,43,43,46,-21,22,46,49,43,35,-32};
print_1(str[0],65);
print_2(str[1],65);
print_3(str[2],65);
print_4(str[3],65);
print_5(str[4],65);
print_6(str[5],65);
print_7(str[6],65);
print_8(str[7],65);
print_9(str[8],65);
print_10(str[9],65);
print_11(str[10],65);
print_12(str[11],65);
return 0;
}