记录编号 |
589245 |
评测结果 |
AAAAAAAAAA |
题目名称 |
飘雪圣域 |
最终得分 |
100 |
用户昵称 |
┭┮﹏┭┮ |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.480 s |
提交时间 |
2024-07-04 14:09:51 |
内存使用 |
15.08 MiB |
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define in inline
#define db double
#define re register
#define pii pair<int,int>
#define fi first
#define se second
#define pb(x) push_back(x)
#define D(i,a,b) for(re long double i = a;i >= b;i--)
#define F(i,a,b) for(re long long i = a;i <= b;i++)
const int N = 2e5+10,M = 4e6+1e5;
const ll inf = 1e17;
ll read(){
ll x = 0,f = 1;char c = getchar();
for(;c < '0' || c > '9';c = getchar())if(c == '-')f = -1;
for(;c >= '0' && c <= '9';c = getchar())x = (x<<1) + (x<<3) + c-'0';
return x * f;
}
int n,m;
struct made{int l,id; };
vector<made>q[N];
vector<int>a[N];
int ans[N];
struct BIT{
int c[N];
in int lowbit(int x){return x & (-x);}
void add(int x,int val){for(;x <= n;x += lowbit(x))c[x] += val;}
int ask(int x){
int ans = 0;
for(;x > 0;x -= lowbit(x))ans += c[x];
return ans;
}
}t;
int main(){
freopen("icekingdom.in","r",stdin);
freopen("icekingdom.out","w",stdout);
n = read(),m = read();
for(int i = 1;i < n;i++){
int x = read(),y = read();
if(x > y)swap(x,y);
a[y].push_back(x);
}
for(int i = 1;i <= m;i++){
int l = read(),r = read();
q[r].push_back({l,i});
}
for(int i = 1;i <= n;i++){
for(int j = 0;j < a[i].size();j++)t.add(a[i][j],1);
for(int j = 0;j < q[i].size();j++){
int l = q[i][j].l;
ans[q[i][j].id] = i - l + 1 - (t.ask(i) - t.ask(l-1));
}
}
for(int i = 1;i <= m;i++)printf("%d\n",ans[i]);
return cerr << "Time : " << clock() << " ms" << endl, 0;
}