You are given a tree with N nodes. The tree nodes are numbered from 1 to N and have colors C1, C2,. . . , CN initially. You have to handle M instructions on the tree of the following forms:• 0 u c: Change the color of node u to c.• 1 u v: Output the
题目链接:https://vjudge.net/problem/CodeForces-960F You are given a directed graph with n nodes and m edges, with all edges having a certain weight. There might be multiple edges and self loops, and the graph can also be disconnected. You need to choose
题目描述: Description This task is very simple. Given a string S of length n and q queries each query is on the format i j k which means sort the substring consisting of the characters from i to j in non-decreasing order if k = 1 or in non-increasing ord
Count on a tree SPOJ 10628 主席树+LCA(树链剖分实现)(两种存图方式) 题外话,这是我第40篇随笔,纪念一下.<( ̄︶ ̄)↗[GO!] 题意 是说有棵树,每个节点上都有一个值,然后让你求从一个节点到另一个节点的最短路上第k小的值是多少. 解题思路 看到这个题一想以为是树链剖分+主席树,后来写着写着发现不对,因为树链剖分我们分成了一小段一小段,这些小段不能合并起来求第k小,所以这个想法不对.奈何不会做,查了查题解,需要用LCA(最近公共祖先),然后根据主席树具有区间加
题意: 给你N个数,q组操作,操作有两种,查询和改变,查询就是查询当前的这个数上有多少,更改是给你a b k c,每次从a到b,每隔k的数更改一次,之间的数不更改,就相当于跳着更新. 思路:(别人的) (i - a) % k == 0 等价于 i % k == a % k 一共有10中情况 还有枚举所有情况中的小情况 (1)1 2 3 4 5 6 7 8 9..... (2)1 3 5 7 9 11 13 ...... 2 4 6 8
R2D2 and Droid Army time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output An army of n droids is lined up in one row. Each droid is described by m integers a1, a2, -, am, where ai is the number
#include<bits/stdc++.h> using namespace std; const int maxn = 1e5+11; typedef long long ll; char str[maxn]; int a[26][maxn]; struct ST{ #define lc o<<1 #define rc o<<1|1 int num[maxn<<2],lazy[maxn<<2],lazy2[maxn<<2]; vo
#include <bits/stdc++.h> using namespace std; typedef long long LL; const int N=5e2+10; const int INF=0x3f3f3f3f; struct SegT{ int left; int right; int w; }; SegT q[N][N*4]; int dp[N]; int a[N][N]; void Build(int temp,int num,int L,int R) { q[temp][