Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 7aba739

Browse files
committed
.
1 parent 04e4dfb commit 7aba739

9 files changed

+25
-8
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
O(1).
2+
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
1. greedy, sorting. O(sort(n)).
2+
2. find maximum frequency. O(n).
3+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
sorting. O(sort(n)).
2+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Similar to 875. Koko Eating Bananas. O(n) (assuming sqrt takes O(1) time).
2+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
O(1).
2+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
O(n^2).
2+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
sorting, sliding window. O(sort(n)).
2+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
divide into equivalent classes modulo value. greedy. O(n).
2+

‎templates/run_asm.py‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import time
1+
import time,random
22
from ctypes import *
33
import mmap
44

@@ -27,10 +27,10 @@ def compile_asm(s,ftype):
2727
#order: edi,esi,edx,ecx,r8d
2828
#-Ofast -mavx -mavx2
2929

30+
random.seed(1)
3031
n=100000
31-
a=[i%100 for i in range(n)]
32-
a1=(c_int*n)()
33-
for i in range(n): a1[i]=a[i]
32+
a=[randint(0,1000) for i in range(n)]
33+
a1=(c_int*n)(*a)
3434
n1=c_int(n)
3535
d=7
3636
d1=c_int(d)
@@ -56,7 +56,7 @@ def compile_asm(s,ftype):
5656
#t=sum(a)
5757
t=asm_sum(a1,n1)
5858
#print(t)
59-
print('time sum=',time.time()-t1) #4633 vs 446ms
59+
print('time sum=',time.time()-t1) #7726ms vs 647ms
6060

6161

6262
#sum parallel 4
@@ -79,7 +79,7 @@ def compile_asm(s,ftype):
7979
3a: 44 01 d0 add eax,r10d
8080
3d: 44 01 d8 add eax,r11d
8181
40: c3 ret
82-
''',CFUNCTYPE(c_int,POINTER(c_int),c_int)) #189ms
82+
''',CFUNCTYPE(c_int,POINTER(c_int),c_int)) #223ms
8383

8484

8585
#sum -Ofast
@@ -141,7 +141,7 @@ def compile_asm(s,ftype):
141141
8f: 31 d2 xor edx,edx
142142
91: 31 c0 xor eax,eax
143143
93: eb c8 jmp 5d <L3>
144-
''',CFUNCTYPE(c_int,POINTER(c_int),c_int)) #129ms
144+
''',CFUNCTYPE(c_int,POINTER(c_int),c_int)) #169ms
145145

146146

147147
#sum -Ofast -mavx -mavx2
@@ -218,7 +218,7 @@ def compile_asm(s,ftype):
218218
c9: 31 c9 xor ecx,ecx
219219
cb: 31 c0 xor eax,eax
220220
cd: eb 9b jmp 6a <L3>
221-
''',CFUNCTYPE(c_int,POINTER(c_int),c_int)) #59ms
221+
''',CFUNCTYPE(c_int,POINTER(c_int),c_int)) #98ms
222222

223223

224224
#sum x//d where x in a

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /