結果

問題 No.2967 Nana's Plus Permutation Game
ユーザー lif4635
提出日時 2024-11-16 17:01:57
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 834 ms / 2,000 ms
コード長 2,017 bytes
コンパイル時間 497 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 95,104 KB
平均クエリ数 4169.09
最終ジャッジ日時 2024-11-16 17:02:38
合計ジャッジ時間 35,126 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 65
権限があれば一括ダウンロードができます

ソースコード

diff #

"""input"""
#int-input
# input = sys.stdin.readline
def II(): return int(input())
def MI(): return map(int, input().split())
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())

from collections import deque,defaultdict,Counter
mod = 998244353

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

#必ず入っている集合を見つける
#必ず以下マン、以上マンを見つける
# 上72回まで
# その後は8回

n = II()

p = [0]*(n+1)
cnt = [0]*(n+10)

#次どこに向かうかを示しておく
for i in range(1,n+1):
    print(1,i,i)
    to = II()
    p[i] = to
    if to != -1:
        cnt[to] += 1
    

ml = 0
for i in range(1,n+1):
    #必ず始点である
    if cnt[i] == 0:
        now = i
        res = [now]
        while p[now] != -1:
            now = p[now]
            res.append(now)
        
        l = len(res)
        if ml < l:
            ml = l
            one = res[:]

o = one[0]
ans = [one[0],one[1]]
for i in range(n-2):
    print(1,o,ans[-1])
    ans.append(II())

res = [0]*n
for i in range(n):
    res[ans[i]-1] = i+1
print(2,*res)
    
    
0