Codeforces Round #433 C
来源:互联网 发布:软件用户手册英文 编辑:程序博客网 时间:2024/06/08 10:32
#include<cstdio>#include<cstdlib>#include<cstring>#include<cmath>#include<ctime>#include<iostream>#include<algorithm>#include<vector>#include<string>#include<queue>#include<utility>#include<bitset>#include<complex>#include<map>#include<set>#include<unordered_map>#include<unordered_set>using namespace std;#define mem(a,b) memset(a,b,sizeof(a))#define REP(i,a,b) for(int i=a; i<=b; ++i)#define FOR(i,a,b) for(int i=a; i<b; ++i)#define MP make_pairtypedef long long LL;typedef pair<int,int> pii;const int maxn = 2e5;const int maxnode = maxn * 32;int n, m;int tot = 0, rot[maxn + 5];int tree[maxnode + 5], L[maxnode + 5], R[maxnode + 5];int Build(int l, int r) { int rt = tot++; tree[rt] = L[rt] = R[rt] = 0; if(l < r) { int mid = (l + r) >> 1; L[rt] = Build(l, mid); R[rt] = Build(mid + 1, r); } return rt;}int Update(int x, int l, int r, int pos) { int rt = tot++; tree[rt] = tree[x] + 1, L[rt] = L[x], R[rt] = R[x]; if(l < r) { int mid = (l + r) >> 1; if(pos <= mid) L[rt] = Update(L[x], l, mid, pos); else R[rt] = Update(R[x], mid + 1, r, pos); } return rt;}int Query(int rt1, int rt2, int l, int r, int ll, int rr) { if(ll <= l && r <= rr) return tree[rt2] - tree[rt1]; int mid = (l + r) >> 1, res = 0; if(ll <= mid) res += Query(L[rt1], L[rt2], l, mid, ll, rr); if(mid + 1 <= rr) res += Query(R[rt1], R[rt2], mid + 1, r, ll, rr); return res;}inline LL S2(LL tn) { return tn * (tn - 1) / 2;}int main() { int a, l, r, d, u; scanf("%d%d", &n, &m); rot[0] = Build(1, n); for(int i = 1; i <= n; ++i) { scanf("%d", &a); rot[i] = Update(rot[i - 1], 1, n, a); } LL sum = S2(n), ans, tmp; for(int i = 1; i <= m; ++i) { scanf("%d%d%d%d", &l, &d, &r, &u); ans = sum - S2(l - 1) - S2(n - r); if(d - 1 >= 1) { tmp = Query(rot[0], rot[n], 1, n, 1, d - 1); ans -= S2(tmp); tmp = Query(rot[0], rot[l - 1], 1, n, 1, d - 1); ans += S2(tmp); tmp = Query(rot[r], rot[n], 1, n, 1, d - 1); ans += S2(tmp); } if(u + 1 <= n) { tmp = Query(rot[0], rot[n], 1, n, u + 1, n); ans -= S2(tmp); tmp = Query(rot[0], rot[l - 1], 1, n, u + 1, n); ans += S2(tmp); tmp = Query(rot[r], rot[n], 1, n, u + 1, n); ans += S2(tmp); } printf("%lld\n", ans); } return 0;}
阅读全文
0 0
- Codeforces Round #433 C
- Codeforces Round#433 C Planning
- Codeforces Round #433 C. Planning(贪心)
- Codeforces Round #433 (2)C:Planning
- Codeforces Round #433 (Div. 2) C. Planning
- Codeforces Round #433 Div. 2 C
- Codeforces Round #433 (Div. 2) C. Planning
- Codeforces Round #213C
- Codeforces Round#260C
- Codeforces Round 338 C
- Codeforces Round #412 C
- Codeforces Round #409 C
- Codeforces Round #202 C
- Codeforces round 181 div2 C
- codeforces div2 round#231 C
- codeforces div2 round#230 C
- Codeforces Testing Round #10 C
- C. Exams(Codeforces Round #274)
- 初识SR-IOV
- 十一、Shell test命令
- GSON转换集合
- python简单爬虫(获取图片)
- ProgressBar
- Codeforces Round #433 C
- 对下列数据进行操作
- 关于Lan和Wan网口分配配置
- null排序用法
- taskctl的后台字符界面登录不了解决办法
- Java带样式导出excle(poi)
- PHP的魔术方法
- SpringMVC——处理模型数据
- json时间字符串带T