-
Notifications
You must be signed in to change notification settings - Fork 0
/
Cvjetići(z-trening).cpp
51 lines (48 loc) · 978 Bytes
/
Cvjetići(z-trening).cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <cstdio>
#include <cstring>
#include <iostream>
#include <math.h>
#include <string>
#include <sstream>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <ctime>
#include <time.h>
#include <string.h>
#include <algorithm>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
using namespace std;
const int maxn = 100001;
int fw[maxn+1];
inline void ins( int a, int b ){
for( int x = a; x < maxn; x += x& -x )
fw[x] += b;
}
inline int query( int a ){
int ret = 0;
for( int x = a; x > 0; x -= x& -x )
ret += fw[x];
return ret;
}
inline int cvjet( int l, int r ){
int a,b;
a = query( l );
b = query( r );
ins( l, -a ), ins( l+1, a );
ins( r, -b ), ins( r+1, b );
ins( l+1, 1 ), ins( r, -1 );
return a+b;
}
int main(){
int n,l,r;
scanf("%d", &n);
for( int x = 0; x < n; x++ ){
scanf("%d %d", &l, &r);
printf("%d\n", cvjet(l, r));
}
}