結果

問題 No.2956 Substitute with Average
ユーザー lif4635lif4635
提出日時 2024-11-08 21:52:10
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 4,036 bytes
コンパイル時間 203 ms
コンパイル使用メモリ 82,560 KB
実行使用メモリ 227,468 KB
最終ジャッジ日時 2024-11-08 21:52:29
合計ジャッジ時間 11,200 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 52 ms
55,424 KB
testcase_01 AC 57 ms
55,808 KB
testcase_02 AC 53 ms
55,424 KB
testcase_03 WA -
testcase_04 AC 52 ms
55,424 KB
testcase_05 WA -
testcase_06 AC 53 ms
55,808 KB
testcase_07 WA -
testcase_08 AC 52 ms
55,296 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 514 ms
227,468 KB
testcase_19 AC 504 ms
206,656 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 463 ms
221,160 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

def II(): return int(input())
def MI(): return map(int, input().split())
def TI(): return tuple(MI())
def LI(): return list(MI())
#str-input
def SI(): return input()
def MSI(): return input().split()
def SI_L(): return list(SI())
def SI_LI(): return list(map(int, SI()))
#multiple-input
def LLI(n): return [LI() for _ in range(n)]
def LSI(n): return [SI() for _ in range(n)]
#1-indexを0-indexでinput
def MI_1(): return map(lambda x:int(x)-1, input().split())
def TI_1(): return tuple(MI_1())
def LI_1(): return list(MI_1())
class fenwick_tree():
    n=1
    data=[0 for i in range(n)]
    def __init__(self,N):
        self.n=N
        self.data=[0 for i in range(N)]
    def add(self,p,x):
        assert 0<=p<self.n,"0<=p<n,p={0},n={1}".format(p,self.n)
        p+=1
        while(p<=self.n):
            self.data[p-1]+=x
            p+=p& -p
    def sum(self,l,r):
        assert (0<=l and l<=r and r<=self.n),"0<=l<=r<=n,l={0},r={1},n={2}".format(l,r,self.n)
        return self.sum0(r)-self.sum0(l)
    def sum0(self,r):
        s=0
        while(r>0):
            s+=self.data[r-1]
            r-=r&-r
        return s
class dsu():
    n=1
    parent_or_size=[-1 for i in range(n)]
    def __init__(self,N):
        self.n=N
        self.parent_or_size=[-1 for i in range(N)]
    def merge(self,a,b):
        assert 0<=a<self.n, "0<=a<n,a={0},n={1}".format(a,self.n)
        assert 0<=b<self.n, "0<=b<n,b={0},n={1}".format(b,self.n)
        x=self.leader(a)
        y=self.leader(b)
        if x==y:
            return x
        if (-self.parent_or_size[x]<-self.parent_or_size[y]):
            x,y=y,x
        self.parent_or_size[x]+=self.parent_or_size[y]
        self.parent_or_size[y]=x
        return x
    def same(self,a,b):
        assert 0<=a<self.n, "0<=a<n,a={0},n={1}".format(a,self.n)
        assert 0<=b<self.n, "0<=b<n,b={0},n={1}".format(b,self.n)
        return self.leader(a)==self.leader(b)
    def leader(self,a):
        assert 0<=a<self.n, "0<=a<n,a={0},n={1}".format(a,self.n)
        if (self.parent_or_size[a]<0):
            return a
        self.parent_or_size[a]=self.leader(self.parent_or_size[a])
        return self.parent_or_size[a]
    def size(self,a):
        assert 0<=a<self.n, "0<=a<n,a={0},n={1}".format(a,self.n)
        return -self.parent_or_size[self.leader(a)]
    def groups(self):
        leader_buf=[0 for i in range(self.n)]
        group_size=[0 for i in range(self.n)]
        for i in range(self.n):
            leader_buf[i]=self.leader(i)
            group_size[leader_buf[i]]+=1
        result=[[] for i in range(self.n)]
        for i in range(self.n):
            result[leader_buf[i]].append(i)
        result2=[]
        for i in range(self.n):
            if len(result[i])>0:
                result2.append(result[i])
        return result2


def lis(l): #最長増加部分列
    n = len(l)
    tmp = [] # いまi文字目に使える最小
    idxlist = [None] * n # l[i]が使われた場所
    for i in range(n):
        numidx = bisect_right(tmp, l[i])
        if numidx == len(tmp):
            tmp.append(l[i])
        else:
            tmp[numidx] = l[i]
        idxlist[i] = numidx

    # LIS復元
    look = len(tmp) - 1
    ans = [0] * (look + 1)
    idx = [0] * (look + 1)
    # 後ろから見ていく
    for i in range(n-1,-1,-1):
        if idxlist[i] == look:
            ans[look] = l[i] # ansを確定
            idx[look] = i
            look -= 1
    return ans,idx

from bisect import bisect_left,bisect_right
from heapq import heapify,heappop,heappush,heappushpop,merge
from collections import deque,defaultdict,Counter

inf = 1<<60
mod = 10**9+7

n = II()
a = LI()

ans = n*(n+1)//2 + 1
for ave in range(1,30):
    #コレだけの差があるよ
    b = [i-ave for i in a]
    
    cnt = defaultdict(int)
    cnt[0] = 1
    s = 0
    for i in range(n):
        s += b[i]
        
        if b[i] == 0:
            ans -= cnt[s]
            # print(cnt,ave)
        cnt[s] += 1
        
    
    # print(ave,cnt)

print(ans)
    
        
0