NC15519. 是是非非
描述
坎为水,险阳失道,渊深不测;离为火,依附团结,光明绚丽。
坎卦:水洊至,习坎;君子以常德行,习教事。一轮明月照水中,只见影儿不见踪,愚夫当财下去取,摸来摸去一场空。
离卦:明两作,离,大人以继明照四方。官人来占主高升,庄农人家产业增,生意买卖利息厚,匠艺占之大亨通。
输入描述
第一行两个正整数,表示有
个石堆,
次操作。
第二行个整数,第
个数
表示第
个石堆初始有
个石子。
接下去行,每行两个正整数
,表示把第
堆石子的个数修改成
。操作是累计的,也就是说,每次操作是在上一次操作结束后的状态上操作的。
输出描述
共行,输出每次操作之后先手是否有必胜策略。
如果有,输出,否则输出
。
示例1
输入:
5 4 6 7 3 4 5 1 6 2 1 2 4 5 5
输出:
Kan Kan Li Li
Python(2.7.3) 解法, 执行用时: 316ms, 内存消耗: 11420K, 提交时间: 2018-04-21 19:56:45
from operator import xor n, q = map(int, raw_input().split()) a = map(int, raw_input().split()) s = reduce(xor, a) for _ in xrange(q): x, y = map(int, raw_input().split()) s = s ^ a[x - 1] ^ y a[x - 1] = y print 'Li' if s == 0 else 'Kan'
C++11(clang++ 3.9) 解法, 执行用时: 309ms, 内存消耗: 2628K, 提交时间: 2020-01-28 16:50:14
#include<bits/stdc++.h> #define rep(i,s,e) for(int i=s; i<e; ++i) using namespace std; int n,q,s,a[100005]; int main(){ cin>>n>>q; rep(i,1,n+1) cin>>a[i],s^=a[i]; while(q--){ int x,y; cin>>x>>y; s^=a[x]^y; a[x]=y; puts(s?"Kan":"Li"); } }
Python3 解法, 执行用时: 812ms, 内存消耗: 16216K, 提交时间: 2022-06-18 09:15:16
n,q=map(int,input().split()) a=list(map(int,input().split())) s=0 for _ in a:s^=_ for _ in range(q): x,y=map(int,input().split()) s^=a[x-1]^y a[x-1]=y print('Kan'if s else'Li')