我是靠谱客的博主 自信水池,这篇文章主要介绍Dylans loves sequence HDU - 5273,现在分享给大家,希望可以做个参考。

朴素莫队加树状数组 朴素莫队加树状数组 朴素莫队加树状数组
复杂度为 n 根号 n l o g n 显然对于 1 e 5 的数据量超时了 复杂度为n根号nlogn显然对于1e5的数据量超时了 复杂度为n根号nlogn显然对于1e5的数据量超时了
以后有空再学二次离线莫队 以后有空再学二次离线莫队 以后有空再学二次离线莫队

复制代码
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#include<iostream> #include<cstring> #include<algorithm> #include<cmath> #include<vector> using namespace std; const int N = 1e5 + 10; int a[N], c[N], ans[N]; int n, m; int siz; struct node{ int l, r, k; }q[N]; vector<int> vec; inline int read() { int s = 0, w = 1; char ch = getchar(); while (ch<'0' || ch>'9') { if (ch == '-')w = -1; ch = getchar(); } while (ch >= '0'&&ch <= '9') s = s * 10 + ch - '0', ch = getchar(); return s * w; } bool cmp1(node a, node b) { if(a.l/siz == b.l/siz) return a.r < b.r; return a.l/siz < b.l/siz; } int lowbit(int x){ return x & -x; } void add(int x, int v) { for(int i = x; i <= n; i += lowbit(i)) { c[i] += v; } } int query(int x) { int res = 0; for(int i = x; i > 0; i -= lowbit(i)) { res += c[i]; } return res; } int find(int x) { int l = 0, r = vec.size(); while(l < r) { int mid = l + r >> 1; if(vec[mid] >= x) { r = mid; } else l = mid + 1; } return l + 1; } int main(){ n = read(); m = read(); siz = (int)sqrt(n); for(int i = 1; i <= n; i ++) { a[i] = read(); vec.push_back(a[i]); } sort(vec.begin(), vec.end()); vec.erase(unique(vec.begin(), vec.end()), vec.end()); int p = vec.size(); for(int i = 0; i < m; i ++) { q[i].l = read(); q[i].r = read(); q[i].k = i; } sort(q, q+m, cmp1); int l = 1, r = 0; int res = 0; for(int i = 0; i < m; i ++) { while(r < q[i].r) { r ++; int t = find(a[r]); res += (query(p)-query(t)); add(t, 1); } while(r > q[i].r) { int t = find(a[r]); if(c[t]) { res -= (query(p)-query(t)); add(t, -1); } r --; } while(l < q[i].l) { int t = find(a[l]); if(c[t]) { res -= query(t-1); add(t, -1); } l ++; } while(l > q[i].l) { l --; int t = find(a[l]); res += query(t-1); add(t, 1); } ans[q[i].k] = res; } for(int i = 0; i < m; i ++) { printf("%dn", ans[i]); } return 0; }

最后

以上就是自信水池最近收集整理的关于Dylans loves sequence HDU - 5273的全部内容,更多相关Dylans内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(102)

评论列表共有 0 条评论

立即
投稿
返回
顶部