1537: [Example 3] tree outside the school
Time limit: 1000 ms Memory Limit: 524288 KB
Submissions: 497 number by: 216
Description [title]
From the original title: Vijos P1448
There are a lot of trees outside the school, the school decided at some point in a certain period of planted tree with guarantee any one time two of the same kind of tree does not appear, the existing two actions:
K = . 1 K =. 1, the read L , r L, r represents L L to r planted tree with between r, the type of each operation are different kinds of trees;
K = 2 K = 2, the read L , r L, r represents interrogation L L the r number r between the trees.
Note: Each location can be repeated to plant trees.
[Enter]
The first line n- , m n-, m represents a road length as n- n-, a total of m m operations;
Subsequently m m behavior m m operations.
[Output]
For each of the K = 2 K = 2 output an answer.
[Sample input]
5 4 1 1 3 2 2 5 1 2 4 2 3 5
[Sample Output]
1 2
【prompt】
Data range and tips:
For 20% of the data, . 1 ≤ n- , m ≤ 100 1 ≦ n, m≤100;
% To 60% of the data, . 1 ≤ n- ≤ 10 . 3 , . 1 ≤ m ≤ . 5 × 10 . 4 1≤n≤103,1≤m≤5 × 104;
% For 100% of the data, . 1 ≤ n- , m ≤ . 5 × 10 . 4 1 ≦ n, m≤5 × 104, to ensure L , R & lt > 0 L, R & lt> 0.
【source】
#include<bits/stdc++.h> using namespace std; int c1[50005],c2[50005]; int low(int x){return x&(-x);} int find(int l,int r){ int ans=0; for(int i=r;i;i-=low(i))ans+=c1[i]; for(int i=l-1;i;i-=low(i))ans-=c2[i]; return ans; } int main(){ int n,m; scanf("%d%d",&n,&m); for(int i=1;i<=m;i++){ int k,l,r; scanf("%d%d%d",&k,&l,&r); if(k==1){ for(int i=l;i<=n+1;i+=low(i))c1[i]++; for(int i=r;i<=n+1;i+=low(i))c2[i]++; } else printf("%d\n",find(l,r)); } }