Skip to content

Commit 26531b4

Browse files
committed
.
1 parent faf5350 commit 26531b4

File tree

37 files changed

+142
-45
lines changed

37 files changed

+142
-45
lines changed

0101-0200/147. Insertion Sort List 16ms.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ struct List{
2222
struct node{
2323
node *pre,*next;int key;
2424
}a[N],*head;int a1;
25-
void clear(){head=a; a1=0; head->pre=head->next=0; head->key=-(1<<30);}
25+
void clear(){head=a; a1=0; head->pre=head->next=0; head->key=-(1<<30);}
2626
List(){clear();}
2727
void insert(node *x,int key){
2828
node *y=a+(++a1);y->key=key;
@@ -74,4 +74,3 @@ class Solution {
7474
}
7575
};
7676

77-

0201-0300/211. Design Add and Search Words Data Structure 40ms.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,3 @@ int _IO=[](){
4444
return 0;
4545
}();
4646

47-

0201-0300/294. Flip Game II 0ms.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,3 @@ class Solution {
1717
}
1818
};
1919

20-

0301-0400/338. Counting Bits 0ms_hack.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ int _main=[](){
7979
for (int i=cur+1;i<=n;++i)c[i]=c[i>>1]+(i&1);
8080
cur=max(cur,n);
8181
print(c,n+1);
82-
}
82+
}
8383
exit(0);
8484
return 0;
8585
}();

0501-0600/546. Remove Boxes 12ms.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,3 @@ class Solution {
2626
}
2727
};
2828

29-

0501-0600/555. Split Concatenated Strings 24ms.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -129,4 +129,3 @@ class Solution {
129129
}
130130
};
131131

132-

0601-0700/644. Maximum Average Subarray II 80ms.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,3 @@ int _IO=[](){
2424
return 0;
2525
}();
2626

27-

0701-0800/711. Number of Distinct Islands II 40ms.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,3 @@ int _IO=[](){
7878
return 0;
7979
}();
8080

81-

0701-0800/792. Number of Matching Subsequences 80ms.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,3 @@ int _IO=[](){
3434
return 0;
3535
}();
3636

37-

0901-1000/952. Largest Component Size by Common Factor 60ms.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,3 @@ int _IO=[](){
4545
return 0;
4646
}();
4747

48-

0901-1000/954. Array of Doubled Pairs 192ms.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,3 @@ int _IO=[](){
3131
return 0;
3232
}();
3333

34-

1101-1200/1135. Connecting Cities With Minimum Cost 232ms.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,3 @@ int _IO=[](){
6868
return 0;
6969
}();
7070

71-

1101-1200/1146. Snapshot Array 148ms.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -121,4 +121,3 @@ int _IO=[](){
121121
return 0;
122122
}();
123123

124-

1101-1200/1168. Optimize Water Distribution in a Village 192ms.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,3 @@ int _IO=[](){
7474
return 0;
7575
}();
7676

77-

1101-1200/1200. Minimum Absolute Difference 72ms.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,3 @@ int _IO=[](){
8080
return 0;
8181
}();
8282

83-

1201-1300/1216. Valid Palindrome III 4ms.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -171,4 +171,3 @@ class Solution {
171171
}
172172
};
173173

174-

1201-1300/1283. Find the Smallest Divisor Given a Threshold 4ms.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ class Solution {
5454
}
5555
int s1=n; d=l; for (int i=0;i<n;++i)a[i]-=1,s1+=a[i]/d;
5656
assert(s1<=t);
57-
if (t-s1>delta*2){
58-
s1=n; d=l-1; for (int i=0;i<n;++i)s1+=a[i]/d;
59-
if (s1>t)return l;
60-
}
61-
assert(t-s1<=delta*2);
57+
if (t-s1>delta*2){
58+
s1=n; d=l-1; for (int i=0;i<n;++i)s1+=a[i]/d;
59+
if (s1>t)return l;
60+
}
61+
assert(t-s1<=delta*2);
6262
if (s1>t)return d+1;
6363
reduce(&a[0],n,t+1-s1);
6464
find(&a[0],min(n,t+1-s1),t+1-s1);

1301-1400/1353. Maximum Number of Events That Can Be Attended 340ms.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,3 @@ int _IO=[](){
6060
return 0;
6161
}();
6262

63-

1401-1500/1429. First Unique Number 292ms.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,3 @@ int _IO=[](){
4444
return 0;
4545
}();
4646

47-

1401-1500/1483. Kth Ancestor of a Tree Node 308ms.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,3 @@ int _IO=[](){
7373
return 0;
7474
}();
7575

76-

1501-1600/1505. Minimum Possible Integer After at Most K Adjacent Swaps On Digits 24ms.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,3 @@ int _IO=[](){
6262
return 0;
6363
}();
6464

65-

1501-1600/1520. Maximum Number of Non-Overlapping Substrings 200ms.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,3 @@ class Solution {
2929
}
3030
};
3131

32-

1501-1600/1554. Strings Differ by One Character 20ms.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,3 @@ int _IO=[](){
4545
return 0;
4646
}();
4747

48-

1601-1700/1627. Graph Connectivity With Threshold 284ms.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,3 @@ int _IO=[](){
4444
return 0;
4545
}();
4646

47-

1601-1700/1675. Minimize Deviation in Array 196ms.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,3 @@ int _IO=[](){
3737
return 0;
3838
}();
3939

40-

1601-1700/1675. Minimize Deviation in Array 56ms.cpp

+3-4
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@ class Solution {
99
for (int i=0;i<n;++i)ma=max(ma,a[i]>>__builtin_ctz(a[i]));
1010
int low=ma,c=__builtin_clz(ma);
1111
for (int i=0;i<n;++i){
12-
int &t=a[i]; t<<=t&1;
12+
int &t=a[i]; t<<=t&1;
1313
if (t>=ma){
1414
t>>=c-__builtin_clz(t);
15-
t>>=t>ma;
15+
t>>=t>ma;
1616
b[b1++]=t;
1717
}
1818
else low=min(low,t);
1919
mi=min(mi,t);
2020
}
2121
int ans=ma-mi,i0=low==mi?32:__builtin_clz(low-mi);
22-
b[b1++]=low;
22+
b[b1++]=low;
2323
for (int i=0;i<b1;++i)if (b[i]<=low){
2424
int j=b[i]==mi?32:__builtin_clz(b[i]-mi);
2525
vmin[j]=min(vmin[j],b[i]); vmax[j]=max(vmax[j],b[i]);
@@ -40,4 +40,3 @@ int _IO=[](){
4040
return 0;
4141
}();
4242

43-
Binary file not shown.

1701-1800/1713. Minimum Operations to Make a Subsequence 224ms.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,3 @@ int _IO=[](){
9494
return 0;
9595
}();
9696

97-

1701-1800/1726. Tuple with Same Product 64ms_array.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,3 @@ class Solution {
1515
}
1616
};
1717

18-

1701-1800/1726. Tuple with Same Product 68ms.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ namespace Hash{
2121
class Solution {
2222
public:
2323
int tupleSameProduct(vector<int>& a) {
24-
int n=a.size(),ans=0; ++T;
24+
int n=a.size(),ans=0; ++T;
2525
for (int *i=&a[0],*end=i+n;i!=end;++i)
2626
for (int *j=i+1;j!=end;++j)insert(*i*(*j));
2727
for (int *i=&a[0],*end=i+n;i!=end;++i)
@@ -31,4 +31,3 @@ class Solution {
3131
}
3232
};
3333

34-

1701-1800/1760. Minimum Limit of Balls in a Bag 48ms_sampling.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ class Solution {
5454
}
5555
int s1=n; d=l; for (int i=0;i<n;++i)a[i]-=1,s1+=a[i]/d;
5656
assert(s1<=t);
57-
if (t-s1>delta*2){
58-
s1=n; d=l-1; for (int i=0;i<n;++i)s1+=a[i]/d;
59-
if (s1>t)return l;
60-
}
61-
assert(t-s1<=delta*2);
57+
if (t-s1>delta*2){
58+
s1=n; d=l-1; for (int i=0;i<n;++i)s1+=a[i]/d;
59+
if (s1>t)return l;
60+
}
61+
assert(t-s1<=delta*2);
6262
if (s1>t)return d+1;
6363
reduce(&a[0],n,t+1-s1);
6464
find(&a[0],min(n,t+1-s1),t+1-s1);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
const int N=405,W=64,NL=2,S=256,inf=~0u>>1;
2+
typedef unsigned long long ull;
3+
void bool_mat_mul(int a[],int b[],int c[],int n){ //O(n^3/(w log n))
4+
static ull f[N/W+1][N/NL][N/W+1],B[N/NL][N],ans[N][N/W+1];
5+
int L=max((int)floor(log2(max(n/W,1))),1),n1=(n-1)/L+1,n2=(n-1)/W+1;
6+
for (int i=0;i<(1<<L);++i)
7+
for (int j=0;j<n1;++j)
8+
memset(f[i][j],0,sizeof(ull)*n2);
9+
for (int i=0;i<n;++i)memset(ans[i],0,sizeof(ull)*n2);
10+
for (int i=0;i<n1;++i)
11+
for (int j=0;j<n;++j){
12+
B[i][j]=0; int l=min(L,n-i*L);
13+
for (int k=0;k<l;++k)if (b[(i*L+k)*n+j])B[i][j]|=1ull<<k;
14+
}
15+
for (int I=0;I<(1<<L);++I)
16+
for (int i=0;i<n1;++i)
17+
for (int j=0;j<n;++j)
18+
if (I&B[i][j])f[I][i][j/W]|=1ull<<j%W;
19+
for (int i=0;i<n1;++i)
20+
for (int j=0;j<n;++j){
21+
ull x=0; int l=min(L,n-i*L);
22+
for (int k=0;k<l;++k)if (a[j*n+(i*L+k)])x|=1ull<<k;
23+
//for (int k=0;k<n2;++k)ans[j][k]|=f[x][i][k];
24+
ull *startA=ans[j],*startB=f[x][i],*endA=ans[j]+n2;
25+
while (startA!=endA)*startA++|=*startB++;
26+
}
27+
for (int i=0;i<n;++i)
28+
for (int j=0;j<n;++j)c[i*n+j]=(ans[i][j/W]&(1LL<<j%W))>0;
29+
}
30+
bitset<S> c[N][N/S+1];
31+
int d[N],_d[N],id[N],rid[N],a[N*N],b[N*N],f[N*N],mark[N][N];
32+
inline bool cmp(int x,int y){return d[x]<d[y];}
33+
class Solution {
34+
public:
35+
int minTrioDegree(int n, vector<vector<int>>& edges) {
36+
int ans=inf;
37+
for (int i=0;i<n;++i){
38+
d[i]=0,id[i]=i;
39+
for (int j=0;j<(n-1)/S+1;++j)c[i][j].reset();
40+
}
41+
for (auto &e:edges){
42+
int x=--e[0],y=--e[1];
43+
++d[x]; ++d[y];
44+
}
45+
sort(id,id+n,cmp);
46+
for (int i=0;i<n;++i)rid[id[i]]=i,_d[i]=d[i];
47+
for (int i=0;i<n;++i)d[i]=_d[id[i]];
48+
for (auto &e:edges){
49+
int x=rid[e[0]],y=rid[e[1]]; if (x>y)swap(x,y);
50+
c[x][y/S].set(y%S,1);
51+
}
52+
for (int i=0;i<n;++i)
53+
for (int j=0;j<n;++j)a[i*n+j]=b[i*n+j]=0,mark[i][j]=c[i][j/S][j%S];
54+
for (int I=0;I*S<n;++I){
55+
for (int i=0;i<n;++i)
56+
for (int j=0;j<S&&I*S+j<n;++j)a[i*n+I*S+j]=b[(I*S+j)*n+i]=c[i][I][j];
57+
bool_mat_mul(a,b,f,n);
58+
for (int i=0;i<n-2;++i)
59+
for (int j=i+1;j<n-1;++j)if (mark[i][j]&&f[i*n+j]){
60+
mark[i][j]=0;
61+
int k=(c[i][I]&c[j][I])._Find_first();
62+
ans=min(ans,d[i]+d[j]+d[I*S+k]);
63+
}
64+
}
65+
return ans<inf?ans-6:-1;
66+
}
67+
};
68+
69+
//IO
70+
int _IO=[](){
71+
ios::sync_with_stdio(0);
72+
cin.tie(0); //cout.tie(0);
73+
return 0;
74+
}();
75+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
const int N=405,W=64,inf=~0u>>1;
2+
bitset<N> c[N];
3+
int d[N],_d[N],id[N],rid[N];
4+
inline bool cmp(int x,int y){return d[x]<d[y];}
5+
class Solution {
6+
public:
7+
int minTrioDegree(int n, vector<vector<int>>& edges) {
8+
int ans=inf;
9+
for (int i=0;i<n;++i)d[i]=0,id[i]=i,c[i].reset();
10+
for (auto &e:edges){
11+
int x=--e[0],y=--e[1];
12+
++d[x]; ++d[y];
13+
}
14+
sort(id,id+n,cmp);
15+
for (int i=0;i<n;++i)rid[id[i]]=i,_d[i]=d[i];
16+
for (int i=0;i<n;++i)d[i]=_d[id[i]];
17+
for (auto &e:edges){
18+
int x=rid[e[0]],y=rid[e[1]]; if (x>y)swap(x,y);
19+
c[x].set(y,1);
20+
}
21+
for (int i=0;i<n-2;++i){
22+
if (d[i]*3>=ans)break;
23+
for (int j=i+1;j<n-1;++j)if (c[i][j]){
24+
if (d[i]+d[j]*2>=ans)break;
25+
int k=(c[i]&c[j])._Find_first();
26+
if (k<n)ans=min(ans,d[i]+d[j]+d[k]);
27+
}
28+
}
29+
return ans<inf?ans-6:-1;
30+
}
31+
};
32+
33+
//IO
34+
int _IO=[](){
35+
ios::sync_with_stdio(0);
36+
cin.tie(0); //cout.tie(0);
37+
return 0;
38+
}();
39+
Binary file not shown.

figs/1761.png

201 KB
Loading

references.bib

+10
Original file line numberDiff line numberDiff line change
@@ -1436,6 +1436,16 @@ @article{chan2010more
14361436
publisher={SIAM}
14371437
}
14381438

1439+
@inproceedings{vassilevska2009finding,
1440+
title={Finding, minimizing, and counting weighted subgraphs},
1441+
author={Vassilevska, Virginia and Williams, Ryan},
1442+
booktitle={Proceedings of the forty-first annual ACM symposium on Theory of computing},
1443+
pages={455--464},
1444+
year={2009}
1445+
}
1446+
1447+
1448+
14391449

14401450

14411451

template.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,7 @@ struct BitSet{
392392
if (res==S+1)res=0;
393393
return res;
394394
}
395+
int _Find_first(){return ffs();}
395396
uint to_uint(){
396397
correction();
397398
return a[0];
@@ -450,9 +451,8 @@ int _main=[](){
450451
while (1){
451452
if (!read_next('['))break;
452453

453-
}
454+
}
454455
exit(0);
455456
return 0;
456457
}();
457458

458-

0 commit comments

Comments
 (0)