题目链接:hdu 5306 Gorgeous Sequence
和普通的线段树一样一个标记值T,然后另外加一个C值记录以u为根节点的子树下有多少个叶子节点被T值控制。每次修改时,dfs到叶子节点之后在修改该节点。维护sum值时只要额外加上T值控制下的节点。加了个输入外挂,时间少了将近1000ms。
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn = 1000000 + 5;
typedef long long ll;
#define lson(x) (x<<1)
#define rson(x) ((x<<1)|1)
/*********** input *************/
char *ch, *ch1, buf[40*1024000+5], buf1[40*1024000+5];
void read(int &x) {
for (++ch; *ch <= 32; ++ch);
for (x = 0; '0' <= *ch; ch++) x &