prime r k g
3 1 1 2
5 1 2 2
17 1 4 3
97 3 5 5
193 3 6 5
257 1 8 3
7681 15 9 17
12289 3 12 11
40961 5 13 3
65537 1 16 3
786433 3 18 10
5767169 11 19 3
7340033 7 20 3
23068673 11 21 3
104857601 25 22 3
167772161 5 25 3
469762049 7 26 3
1004535809 479 21 3
2013265921 15 27 31
2281701377 17 27 3
3221225473 3 30 5
75161927681 35 31 3
77309411329 9 33 7
206158430209 3 36 22
2061584302081 15 37 7
2748779069441 5 39 3
6597069766657 3 41 5
39582418599937 9 42 5
79164837199873 9 43 5
263882790666241 15 44 7
1231453023109121 35 45 3
1337006139375617 19 46 3
3799912185593857 27 47 5
4222124650659841 15 48 19
7881299347898369 7 50 6
31525197391593473 7 52 3
180143985094819841 5 55 6
1945555039024054273 27 56 5
4179340454199820289 29 57 3

看板子学会的求欧拉回路 :)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include <bits/stdc++.h>
/*
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
*/
using namespace std;

const double eps = 1e-10;
const double pi = 3.1415926535897932384626433832795;
const double eln = 2.718281828459045235360287471352;

#define f(i, a, b) for (int i = a; i <= b; i++)
#define scan(x) scanf("%d", &x)
#define mp make_pair
#define pb push_back
#define lowbit(x) (x&(-x))

#define fi first
#define se second
#define SZ(x) int((x).size())
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define summ(a) (accumulate(all(a), 0ll))

typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;

using ll=long long;

int tt,n,m,tot,hd[(int)2e5+9],deg[(int)2e5+9],mk[(int)4e6+9];
bitset<(int)2e6+9> res;
bitset<(int)2e6+9> vis;
struct edge{
int to,nxt;
}e[(int)4e6+9];
inline void add(int u,int v){
e[++tot]={v,hd[u]},hd[u]=tot;
e[++tot]={u,hd[v]},hd[v]=tot;
}

void dfs(int u){
for(int &eg=hd[u];eg;){
if(vis[eg]){eg=e[eg].nxt;continue;}
vis[eg]=vis[eg^1]=1;
res[eg>>1]=eg&1;
dfs(e[eg].to);
}
}

int main()
{
int size(512<<20); // 512M
__asm__ ( "movq %0, %%rsp\n"::"r"((char*)malloc(size)+size));
ios::sync_with_stdio(false);
cin.tie(0);
cin>>tt;
f(sb,1,tt){
tot=1;
vis.reset(),res.reset();
cin>>n>>m;
for(int i=1;i<=n+1;++i)hd[i]=deg[i]=0;
for(int i=1,x,y;i<=m;++i){
cin>>x>>y;
deg[x]+=1,deg[y]+=1;
add(x,y);
}
for(int i=1;i<=n;++i)if(deg[i]&1)add(i,n+1);
for(int i=1;i<=n;++i)dfs(i);
for(int i=1;i<=m;++i)cout<<res[i];
cout<<"\n";
}
exit(0);
}

过年分块写挂了的

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#include <bits/stdc++.h>
/*
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
*/
using namespace std;

const double eps = 1e-10;
const double pi = 3.1415926535897932384626433832795;
const double eln = 2.718281828459045235360287471352;

#define f(i, a, b) for (int i = a; i <= b; i++)
#define scan(x) scanf("%d", &x)
#define mp make_pair
#define pb push_back
#define lowbit(x) (x&(-x))

#define fi first
#define se second
#define SZ(x) int((x).size())
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define summ(a) (accumulate(all(a), 0ll))

typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;

using ll=long long;

const int maxm=1e5+9;

template <class T> inline T read(const T sample) {
T x=0; int f=1; char s;
while((s=getchar())>'9'||s<'0') if(s=='-') f=-1;
while(s>='0'&&s<='9') x=(x<<1)+(x<<3)+(s^48),s=getchar();
return x*f;
}
template <class T> inline void write(const T x) {
if(x<0) return (void) (putchar('-'),write(-x));
if(x>9) write(x/10);
putchar(x%10^48);
}

struct tree{int v,l,r;}tr[maxm*400];
struct operat{int type,x,y;}q[maxm];
int n,m,a[maxm],b[maxm*2],rt[maxm],qs[maxm],tot,cn,tmp[2][23],cnt[2],len;
void change(int &now,int l,int r,int pos,int val){
if(!now)now=++cn;
tr[now].v+=val;
if(l==r)return ;
int mid=(l+r)>>1;
if(pos<=mid)change(tr[now].l,l,mid,pos,val);
else change(tr[now].r,mid+1,r,pos,val);
}

void pre_change(int x,int val){
int k=std::lower_bound(b+1,b+1+tot,a[x])-b;
for(int i=x;i<=n;i+=lowbit(i))change(rt[i],1,tot,k,val);
}

int query(int l,int r,int k){
if(l==r){return b[l];}
int mid=(l+r)>>1,sum=0;
for(int i=1;i<=cnt[1];++i)sum+=tr[tr[tmp[1][i]].l].v;
for(int i=1;i<=cnt[0];++i)sum-=tr[tr[tmp[0][i]].l].v;
if (k<=sum)
{
for (int i=1;i<=cnt[1];i++) tmp[1][i]=tr[tmp[1][i]].l;
for (int i=1;i<=cnt[0];i++) tmp[0][i]=tr[tmp[0][i]].l;
return query(l,mid,k);
}
else
{
for (int i=1;i<=cnt[1];i++) tmp[1][i]=tr[tmp[1][i]].r;
for (int i=1;i<=cnt[0];i++) tmp[0][i]=tr[tmp[0][i]].r;
return query(mid+1,r,k-sum);
}
}

int pre_query(int l,int r,int k){
memset(tmp,0,sizeof(tmp));
cnt[1]=cnt[0]=0;
for(int i=r;i;i-=lowbit(i))tmp[1][++cnt[1]]=rt[i];
for(int i=l-1;i;i-=lowbit(i))tmp[0][++cnt[0]]=rt[i];
return query(1,tot,k);
}

int main()
{
n=read(1),m=read(1);
len=n;
for(int i=1;i<=n;++i)qs[i]=b[i]=a[i]=read(1);
for(int i=1,x,y,z;i<=m;++i){
x=read(1),y=read(1),z=read(1);
q[i]={x,y,z};
if(x==1){
qs[y]+=z;
b[++len]=qs[y];
}
}
sort(b+1,b+1+len);
tot=unique(b+1,b+1+len)-b-1;
for(int i=1;i<=n;++i)pre_change(i,1);
for(int i=1;i<=m;++i){
if(q[i].type==2){
bool ok=0;
ll k=q[i].y-q[i].x+1;
if(k<3){
write(0),putchar('\n');
continue;
}
ll a=pre_query(q[i].x,q[i].y,k),b=pre_query(q[i].x,q[i].y,k-1),c=pre_query(q[i].x,q[i].y,k-2);
k-=2;
while(k){
if(b+c>a){ok=1;break;}
a=b,b=c,k-=1;
if(k)c=pre_query(q[i].x,q[i].y,k);
}
write(ok?a+b+c:0),putchar('\n');
}
else{
pre_change(q[i].x,-1);
a[q[i].x]+=q[i].y;
pre_change(q[i].x,1);
}
}
return 0;
}

1001

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include <bits/stdc++.h>
/*
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
*/
using namespace std;

const double eps = 1e-10;
const double pi = 3.1415926535897932384626433832795;
const double eln = 2.718281828459045235360287471352;

#define f(i, a, b) for (int i = a; i <= b; i++)
#define scan(x) scanf("%d", &x)
#define mp make_pair
#define pb push_back
#define lowbit(x) (x&(-x))

#define fi first
#define se second
#define SZ(x) int((x).size())
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define summ(a) (accumulate(all(a), 0ll))

typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;

using ll=long long;

const int maxn=2e3+9;
int n,m,rt[maxn],cnt,b[maxn],a[maxn],tot;
struct Node{
int l,r,val;
}tr[maxn*20];

inline void build(int &k,int l,int r){
k=++cnt;
if(l==r)return;
int mid=(l+r)>>1;
build(tr[k].l,l,mid),build(tr[k].r,mid+1,r);
}


inline void change(int &k,int kk,int l,int r,int val){
k=++cnt,tr[k]=tr[kk],tr[k].val+=1;
if(l==r)return ;
int mid=(l+r)>>1;
if(val<=mid)change(tr[k].l,tr[kk].l,l,mid,val);
else change(tr[k].r,tr[kk].r,mid+1,r,val);
}

inline int query(int nl,int nr,int l,int r,int k){
int x=tr[tr[nr].l].val-tr[tr[nl].l].val;
if(l==r)return b[l];
int mid=(l+r)>>1;
if(x>=k)return query(tr[nl].l,tr[nr].l,l,mid,k);
return query(tr[nl].r,tr[nr].r,mid+1,r,k-x);
}

ll f[109][109][109];
ll dfs(ll l,ll r,ll cs){
if(f[l][r][cs])return f[l][r][cs];
if(cs==1){
int len=r-l+1;
return f[l][r][cs]=query(rt[l-1],rt[r],1,tot,len-len/20);
}
ll res=0x3f3f3f3f;
for(int i=l;i<n;++i){
res=min(res,dfs(l,i,1)+dfs(i+1,n,cs-1));
}
//cout<<l<<"::"<<r<<"__"<<cs<<"||"<<res<<"\n";
return f[l][r][cs]=res;
}

void solve(){
memset(tr,0,sizeof(tr));
memset(f,0,sizeof(f));
cin>>n>>m;
f(i,1,n)cin>>a[i],b[i]=a[i];
sort(b+1,b+1+n);
tot=unique(b+1,b+n+1)-(b+1);
build(rt[0],1,tot);
f(i,1,n){
int now=lower_bound(b+1,b+1+tot,a[i])-b;
change(rt[i],rt[i-1],1,tot,now);
}
cout<<dfs(1,n,m)<<"\n";
}
ll tt;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin>>tt;
f(sb,1,tt)solve();
return 0;
}

1002

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <bits/stdc++.h>
/*
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
*/
using namespace std;

const double eps = 1e-10;
const double pi = 3.1415926535897932384626433832795;
const double eln = 2.718281828459045235360287471352;

#define f(i, a, b) for (int i = a; i <= b; i++)
#define scan(x) scanf("%d", &x)
#define mp make_pair
#define pb push_back
#define lowbit(x) (x&(-x))

#define fi first
#define se second
#define SZ(x) int((x).size())
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define summ(a) (accumulate(all(a), 0ll))

typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;

using ll=long long;

ll tt,n,a[(int)1e6+9],k1,k2,p;
bitset<(int)1e6+9> vis;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin>>tt;
f(sb,1,tt){
vis.reset();
cin>>n;
f(i,1,n)cin>>a[i];
cin>>k1>>k2>>p;
__int128 res1=0,res2=0,base=100;
for(int i=1;i<=k2;++i)res2+=a[i];
for(int i=k2-k1+1;i<=k2;++i)res1+=a[i];
vis[k2]=k1*res2*p>res1*k2*base;
for(int i=k2+1;i<=n;++i){
res1-=a[i-k1];
res2-=a[i-k2];
res1+=a[i],res2+=a[i];
vis[i]=k1*res2*p>res1*k2*base;
//cout<<i<<"::"<<(long long)(base*(res2*k1-res1*k2)-k1*k2*p)<<"\n";
}
f(i,1,n)cout<<vis[i];
cout<<"\n";
}
return 0;
}

1007

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <bits/stdc++.h>
/*
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
*/
using namespace std;

#define all(x) x.begin(), x.end()
#define f(i, a, b) for (int i = a; i <= b; i++)

using ll=long long;
long long tt,p,q;


void solve(){
cin>>p>>q;
if(p==1&&q==1){
cout<<"sc\n";
return;
}
int cnt=1,qsb=q;
string ans="";
while(!(p==1&&q==1)){
ll fm=q-p,fz=p;
if(fm>fz)ans+="s";
else ans+="c";
p=min(fz,fm),q=max(fz,fm);
}

if(p==1&&q==1&&ans.size()<qsb){
cout<<"sc";
reverse(all(ans));
for(auto it:ans)cout<<"t"<<it;
cout<<"\n";
}
else cout<<"Noooooooo!\n";
}

int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin>>tt;
f(S,1,tt)solve();
return 0;
}

字典树+dp,非常interesting

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include <bits/stdc++.h>
/*
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
*/
using namespace std;

const double eps = 1e-10;
const double pi = 3.1415926535897932384626433832795;
const double eln = 2.718281828459045235360287471352;

#define f(i, a, b) for (int i = a; i <= b; i++)
#define scan(x) scanf("%d", &x)
#define mp make_pair
#define pb push_back
#define lowbit(x) (x&(-x))

#define fi first
#define se second
#define SZ(x) int((x).size())
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define summ(a) (accumulate(all(a), 0ll))

typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;

using ll=long long;
struct trie{
vector<array<int,2>> ch;
vector<array<array<int,2>,2>> val;
trie(){ch.resize(1),val.resize(1);}
void insert(int ai,int i,int dpval){
bitset<30> b1(ai),b2(i);
int now=0;
for(int k=29;~k;--k){
val[now][b1[k]][b2[k]]=max(val[now][b1[k]][b2[k]],dpval);
if(ch[now][b1[k]^b2[k]]==0){
val.push_back({0,0,0,0});
ch.push_back({0,0});
ch[now][b1[k]^b2[k]]=val.size()-1;
}
now=ch[now][b1[k]^b2[k]];
}
}
int query(int aj,int j){
int now=0,ans=0;
bitset<30> b1(aj),b2(j);
for(int k=29;~k;--k){
int i=!b1[k],ai=b2[k];
ans=max(ans,val[now][ai][i]);
now=ch[now][b1[k]^b2[k]];
if(!now)break;
}
return ans;
}
};

int tt,n;

int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin>>tt;
f(Sb,1,tt){
cin>>n;
vi v(n);
for(auto &it:v)cin>>it;
trie t;
int ans=0;
for(int i=0;i<n;++i){
int tmp=t.query(v[i],i);
t.insert(v[i],i,tmp+1);
ans=max(ans,tmp+1);
}
cout<<ans<<"\n";
}
return 0;
}
0%