Submission #22134411


Source Code Expand

Copy
class segtree():
n=1
size=1
log=2
d=[0]
op=None
e=10**15
def __init__(self,V,OP,E):
self.n=len(V)
self.op=OP
self.e=E
self.log=(self.n-1).bit_length()
self.size=1<<self.log
self.d=[E for i in range(2*self.size)]
for i in range(self.n):
self.d[self.size+i]=V[i]
for i in range(self.size-1,0,-1):
self.update(i)
def set(self,p,x):
assert 0<=p and p<self.n
p+=self.size
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
class segtree():
    n=1
    size=1
    log=2
    d=[0]
    op=None
    e=10**15
    def __init__(self,V,OP,E):
        self.n=len(V)
        self.op=OP
        self.e=E
        self.log=(self.n-1).bit_length()
        self.size=1<<self.log
        self.d=[E for i in range(2*self.size)]
        for i in range(self.n):
            self.d[self.size+i]=V[i]
        for i in range(self.size-1,0,-1):
            self.update(i)
    def set(self,p,x):
        assert 0<=p and p<self.n
        p+=self.size
        self.d[p]=x
        for i in range(1,self.log+1):
            self.update(p>>i)
    def get(self,p):
        assert 0<=p and p<self.n
        return self.d[p+self.size]
    def prod(self,l,r):
        assert 0<=l and l<=r and r<=self.n
        sml=self.e
        smr=self.e
        l+=self.size
        r+=self.size
        while(l<r):
            if (l&1):
                sml=self.op(sml,self.d[l])
                l+=1
            if (r&1):
                smr=self.op(self.d[r-1],smr)
                r-=1
            l>>=1
            r>>=1
        return self.op(sml,smr)
    def all_prod(self):
        return self.d[1]
    def max_right(self,l,f):
        assert 0<=l and l<=self.n
        assert f(self.e)
        if l==self.n:
            return self.n
        l+=self.size
        sm=self.e
        while(1):
            while(l%2==0):
                l>>=1
            if not(f(self.op(sm,self.d[l]))):
                while(l<self.size):
                    l=2*l
                    if f(self.op(sm,self.d[l])):
                        sm=self.op(sm,self.d[l])
                        l+=1
                return l-self.size
            sm=self.op(sm,self.d[l])
            l+=1
            if (l&-l)==l:
                break
        return self.n
    def min_left(self,r,f):
        assert 0<=r and r<self.n
        assert f(self.e)
        if r==0:
            return 0
        r+=self.size
        sm=self.e
        while(1):
            r-=1
            while(r>1 & (r%2)):
                r>>=1
            if not(f(self.op(self.d[r],sm))):
                while(r<self.size):
                    r=(2*r+1)
                    if f(self.op(self.d[r],sm)):
                        sm=self.op(self.d[r],sm)
                        r-=1
                return r+1-self.size
            sm=self.op(self.d[r],sm)
            if (r& -r)==r:
                break
        return 0
    def update(self,k):
        self.d[k]=self.op(self.d[2*k],self.d[2*k+1])

N,K = map(int,input().split())
L = [0]*300100
G=segtree(L,max,0)
ans = 0
for _ in range(N):
    a = int(input())
    l = max(0,a-K)
    r = min(300000,a+K)
    v = G.prod(l,r+1)
    G.set(a,v+1)
print(G.all_prod())

Submission Info

Submission Time
Task D - Flat Subsequence
User H20
Language PyPy3 (7.3.0)
Score 400
Code Size 2799 Byte
Status AC
Exec Time 786 ms
Memory 150976 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 1
AC × 31
Set Name Test Cases
Sample example0.txt
All 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, 021.txt, 022.txt, 023.txt, 024.txt, 025.txt, 026.txt, 027.txt, 028.txt, 029.txt, example0.txt
Case Name Status Exec Time Memory
000.txt AC 693 ms 150396 KB
001.txt AC 318 ms 150772 KB
002.txt AC 361 ms 150760 KB
003.txt AC 518 ms 150436 KB
004.txt AC 298 ms 150752 KB
005.txt AC 445 ms 150712 KB
006.txt AC 536 ms 150708 KB
007.txt AC 666 ms 150668 KB
008.txt AC 392 ms 150508 KB
009.txt AC 376 ms 150976 KB
010.txt AC 760 ms 150920 KB
011.txt AC 786 ms 150712 KB
012.txt AC 759 ms 150448 KB
013.txt AC 768 ms 150504 KB
014.txt AC 746 ms 150416 KB
015.txt AC 728 ms 150484 KB
016.txt AC 769 ms 150764 KB
017.txt AC 755 ms 150432 KB
018.txt AC 724 ms 150540 KB
019.txt AC 735 ms 150520 KB
020.txt AC 696 ms 150656 KB
021.txt AC 737 ms 150708 KB
022.txt AC 722 ms 150480 KB
023.txt AC 775 ms 150284 KB
024.txt AC 750 ms 150588 KB
025.txt AC 718 ms 150656 KB
026.txt AC 715 ms 150536 KB
027.txt AC 749 ms 150440 KB
028.txt AC 641 ms 150544 KB
029.txt AC 656 ms 150660 KB
example0.txt AC 105 ms 144484 KB


2025-03-27 (Thu)
02:17:16 +00:00