【题目来源】https://www.luogu.com.cn/problem/P3379【题目描述】 如题,给定一棵有根多叉树,请求出指定两个点直接最近的公共祖先。【输入格式】 第一行包含三个正整数 N,M,S,分别表示树的结点个数、询问的个数和树根结点的序号。 接下来 N−1 行每行包含两个正整数 x,y,表示 x 结点和 y 结点之间有一条直接连接的边(数据保证可以构成树)。 接下来 M 行每
D. 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
传送⻔ 题意 分析 我们用主席树维护每一个数最后一次出现的位置,然后每次查询就在第 r r r棵树上求最小的,位置小于 l l l的数 代码 #include <bits/stdc++.h>#define debug(x) cout<<#x<<":"<<x<<endl;#define dl(x) printf("%lld\n",x);#define di(x) printf("
You are given circular array a0, a1, ..., an - 1. There are two types of operations with it: inc(lf, rg, v) — this operation increases each element on the segment [lf, rg] (inclusively) by v;rmq(lf,
题目:http://acm.hdu.edu.cn/showproblem.php?pid=5443 Problem Description In Land waterless, water is a very limited resource. People always fight for the biggest source of water. Given a sequence
Balanced Lineup Time Limit: 5000MS Memory Limit: 65536KTotal Submissions: 65283 Accepted: 30409Case Time Limit: 2000MS Description For the daily milking, Farmer John's N cows (1 ≤ N ≤ 50,000) alway
说几种比较傻逼的做法: 考虑一个点i,设它前面第一个和它相等的点的位置是 lasti last_i(若没有就是0),设它后面第一个和它相等的点的位置是 nexti next_i(如果没有就是n+1),则它会产生贡献的区间[l,r]要求 lasti+1≤l≤i,i≤r≤nexti−1 last_i+1\le l \le i,i\le r \le next_i-1。所以如果把询问的区间看作平面上的点