結果

問題 No.905 Sorted?
ユーザー hedwig100hedwig100
提出日時 2020-04-12 12:35:08
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
実行時間 -
コード長 2,258 bytes
コンパイル時間 87 ms
コンパイル使用メモリ 12,208 KB
実行使用メモリ 23,820 KB
最終ジャッジ日時 2023-10-22 00:59:39
合計ジャッジ時間 17,117 ms
ジャッジサーバーID
(参考情報)
judge10 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 32 ms
10,400 KB
testcase_01 AC 34 ms
10,400 KB
testcase_02 AC 32 ms
10,396 KB
testcase_03 AC 32 ms
10,400 KB
testcase_04 AC 32 ms
10,400 KB
testcase_05 AC 39 ms
10,844 KB
testcase_06 AC 35 ms
10,644 KB
testcase_07 AC 53 ms
11,704 KB
testcase_08 AC 1,342 ms
16,836 KB
testcase_09 AC 886 ms
16,288 KB
testcase_10 AC 1,219 ms
22,028 KB
testcase_11 AC 772 ms
19,536 KB
testcase_12 AC 897 ms
18,936 KB
testcase_13 AC 792 ms
23,820 KB
testcase_14 AC 1,416 ms
23,812 KB
testcase_15 AC 1,730 ms
19,992 KB
testcase_16 AC 1,688 ms
22,380 KB
testcase_17 AC 1,618 ms
21,872 KB
testcase_18 AC 1,174 ms
21,872 KB
testcase_19 RE -
testcase_20 AC 33 ms
10,400 KB
testcase_21 AC 32 ms
10,400 KB
testcase_22 AC 32 ms
10,400 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

MOD = 10 ** 9 + 7
INF = 10 ** 10
import sys
sys.setrecursionlimit(100000000)
dy = (-1,0,1,0)
dx = (0,1,0,-1)
from collections import deque
from heapq import heapify,heappush,heappop

class SegmentTree():

    def __init__(self,init_val,n,func): #init_valは長さnの配列 O(2n)
        self.unit = 1
        self.size = pow(2,n-1).bit_length() #n以上の最小の2のべき乗
        self.seg = [self.unit]*2*self.size #セグメントツリー本体
        self.f = func #セグ木により異なる関数
        
        for i in range(n):
            self.seg[i+self.size-1] = init_val[i] 
        
        for i in range(self.size-2,-1,-1):
            self.seg[i] = self.f(self.seg[2*i+1],self.seg[2*i+2])
    
    def update(self,k,x): #k番目の要素をxに変更する O(logN)
        k+=self.size-1
        self.seg[k]=x
        while k:
            k=(k-1)//2
            self.seg[k]=self.f(self.seg[2*k+1],self.seg[2*k+2])
    
    def query(self,p,q): #[p,q)のクエリに答える 半開区間であることに注意 O(logN)
        if q<=p:
            return self.unit

        p+=self.size-1
        q+=self.size-2
        res=self.unit

        while q-p>1:

            if (p&1)==0:
                res=self.f(res,self.seg[p])

            if (q&1)==1:
                res=self.f(res,self.seg[q])
                q-=1
            p//=2
            q=(q-1)//2
        
        if p==q:
            res=self.f(res,self.seg[p])
        else:
            res=self.f(self.f(res,self.seg[p]),self.seg[q])
        
        return res

def f(x,y):
    return (x&y)

def main():
    n = int(input())
    a = list(map(int,input().split()))
    
    inc = []
    dec = []
    for i in range(n - 1):
        if a[i] == a[i + 1]:
            inc.append(1)
            dec.append(1)
        elif a[i] < a[i + 1]:
            inc.append(1)
            dec.append(0)
        else:
            inc.append(0)
            dec.append(1)

    st_inc = SegmentTree(inc,n - 1,f)
    st_dec = SegmentTree(dec,n - 1,f)

    q = int(input())
    for _ in range(q):
        l,r = map(int,input().split())
        if l == r:
            print(1,1)
        else:
            print(st_inc.query(l,r),st_dec.query(l,r))

if __name__ =='__main__':
    main()  
0