QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#397551#2670. Arranging shoesismailfateen#10 107ms22124kbC++201.9kb2024-04-24 12:29:462024-07-04 03:37:12

Judging History

你现在查看的是最新测评结果

  • [2024-07-04 03:37:12]
  • 评测
  • 测评结果:10
  • 用时:107ms
  • 内存:22124kb
  • [2024-04-24 12:29:46]
  • 提交

answer

#include "shoes.h"
#include <bits/stdc++.h>
#define mid ((tl + tr) >> 1)
#define lc (node + 1)
#define rc (node + 2 * (mid - tl + 1))
using namespace std;
const int MAXN = 1e5 + 5;
vector<int> pos[2 * MAXN];
bool processed[2 * MAXN];
struct node {
	long long sm, lazy;
};
struct SegmentTree {
	vector<node> tree; 
	void init(int n) {
		tree.resize(2 * n);
	}
	void propagate(int tl, int tr, int node) {
		tree[node].sm += tree[node].lazy * (tr - tl + 1);
		if (tl != tr) {
			tree[lc].lazy += tree[node].lazy;
			tree[rc].lazy += tree[node].lazy;
		}
		tree[node].lazy = 0;
	}
	void update(int tl, int tr, int node, int l, int r, long long val) {
		propagate(tl, tr, node);
		if (tl > r || tr < l) return;
		if (l <= tl && tr <= r) {
			tree[node].lazy += val;
			propagate(tl, tr, node);
			return;
		}
		update(tl, mid, lc, l, r, val), update(mid + 1, tr, rc, l, r, val);
		tree[node].sm = tree[lc].sm + tree[rc].sm;
	}
	long long query(int tl, int tr, int node, int l, int r) {
		propagate(tl, tr, node);
		if (tl > r || tr < l) return 0;
		if (tl >= l && tr <= r) return tree[node].sm;
		return query(tl, mid, lc, l, r) + query(mid + 1, tr, rc, l, r);
	}
};

long long count_swaps(std::vector<int> s) {
	int n = s.size();
	SegmentTree st;
	st.init(2 * MAXN);	
	const int DELTA = MAXN - 3;
	for (int i = n; i; --i)
		pos[s[i - 1] + DELTA].push_back(i);	
	long long ret = 0;
	for (int i = 1; i <= n; ++i) {
		if (processed[i]) continue;
		long long a = pos[s[i - 1] + DELTA].back(), b = pos[DELTA - s[i - 1]].back();
		pos[s[i - 1] + DELTA].pop_back();
		pos[DELTA - s[i - 1]].pop_back();
		processed[a] = processed[b] = true;
		long long x = a + st.query(1, n, 1, a, a), y = b + st.query(1, n, 1, b, b);
		if (s[i - 1] < 0) 
			ret += y - x - 1;
		else 
			ret += y - x;

		if (x + 1 <= y - 1) 
			st.update(1, n, 1, x + 1, y - 1, 1);

	}
	return ret;
}

詳細信息

Subtask #1:

score: 10
Accepted

Test #1:

score: 10
Accepted
time: 0ms
memory: 9352kb

input:

08f55b3f-c300-4051-a472-59ca2a776178
1
-1 1

output:

9ce55564-5404-428a-8d2e-0d809c85101e
OK
0

result:

ok 3 lines

Test #2:

score: 0
Accepted
time: 0ms
memory: 9392kb

input:

08f55b3f-c300-4051-a472-59ca2a776178
1
1 -1

output:

9ce55564-5404-428a-8d2e-0d809c85101e
OK
1

result:

ok 3 lines

Subtask #2:

score: 0
Wrong Answer

Dependency #1:

100%
Accepted

Test #3:

score: 20
Accepted
time: 3ms
memory: 9468kb

input:

08f55b3f-c300-4051-a472-59ca2a776178
2
-1 -2 2 1

output:

9ce55564-5404-428a-8d2e-0d809c85101e
OK
2

result:

ok 3 lines

Test #4:

score: 0
Accepted
time: 0ms
memory: 9464kb

input:

08f55b3f-c300-4051-a472-59ca2a776178
2
-2 1 -1 2

output:

9ce55564-5404-428a-8d2e-0d809c85101e
OK
3

result:

ok 3 lines

Test #5:

score: 0
Accepted
time: 0ms
memory: 9328kb

input:

08f55b3f-c300-4051-a472-59ca2a776178
2
-2 2 -1 1

output:

9ce55564-5404-428a-8d2e-0d809c85101e
OK
0

result:

ok 3 lines

Test #6:

score: 0
Accepted
time: 0ms
memory: 9344kb

input:

08f55b3f-c300-4051-a472-59ca2a776178
2
-1 -2 2 1

output:

9ce55564-5404-428a-8d2e-0d809c85101e
OK
2

result:

ok 3 lines

Test #7:

score: 0
Accepted
time: 0ms
memory: 9272kb

input:

08f55b3f-c300-4051-a472-59ca2a776178
2
-1 2 1 -2

output:

9ce55564-5404-428a-8d2e-0d809c85101e
OK
2

result:

ok 3 lines

Test #8:

score: 0
Accepted
time: 0ms
memory: 9424kb

input:

08f55b3f-c300-4051-a472-59ca2a776178
2
2 -2 -1 1

output:

9ce55564-5404-428a-8d2e-0d809c85101e
OK
1

result:

ok 3 lines

Test #9:

score: 0
Accepted
time: 2ms
memory: 9544kb

input:

08f55b3f-c300-4051-a472-59ca2a776178
2
1 2 -2 -1

output:

9ce55564-5404-428a-8d2e-0d809c85101e
OK
4

result:

ok 3 lines

Test #10:

score: 0
Accepted
time: 0ms
memory: 9352kb

input:

08f55b3f-c300-4051-a472-59ca2a776178
2
2 -2 1 -1

output:

9ce55564-5404-428a-8d2e-0d809c85101e
OK
2

result:

ok 3 lines

Test #11:

score: 0
Accepted
time: 0ms
memory: 9360kb

input:

08f55b3f-c300-4051-a472-59ca2a776178
2
1 2 -2 -1

output:

9ce55564-5404-428a-8d2e-0d809c85101e
OK
4

result:

ok 3 lines

Test #12:

score: -20
Wrong Answer
time: 3ms
memory: 9376kb

input:

08f55b3f-c300-4051-a472-59ca2a776178
3
-3 -2 1 2 3 -1

output:

9ce55564-5404-428a-8d2e-0d809c85101e
OK
6

result:

wrong answer 3rd lines differ - expected: '5', found: '6'

Subtask #3:

score: 0
Wrong Answer

Test #37:

score: 20
Accepted
time: 0ms
memory: 9328kb

input:

08f55b3f-c300-4051-a472-59ca2a776178
2
-2 -2 2 2

output:

9ce55564-5404-428a-8d2e-0d809c85101e
OK
1

result:

ok 3 lines

Test #38:

score: 0
Accepted
time: 3ms
memory: 9288kb

input:

08f55b3f-c300-4051-a472-59ca2a776178
2
-1 1 -1 1

output:

9ce55564-5404-428a-8d2e-0d809c85101e
OK
0

result:

ok 3 lines

Test #39:

score: 0
Accepted
time: 3ms
memory: 9480kb

input:

08f55b3f-c300-4051-a472-59ca2a776178
2
-1 1 -1 1

output:

9ce55564-5404-428a-8d2e-0d809c85101e
OK
0

result:

ok 3 lines

Test #40:

score: 0
Accepted
time: 0ms
memory: 9304kb

input:

08f55b3f-c300-4051-a472-59ca2a776178
2
-2 -2 2 2

output:

9ce55564-5404-428a-8d2e-0d809c85101e
OK
1

result:

ok 3 lines

Test #41:

score: 0
Accepted
time: 3ms
memory: 9272kb

input:

08f55b3f-c300-4051-a472-59ca2a776178
2
-1 1 1 -1

output:

9ce55564-5404-428a-8d2e-0d809c85101e
OK
1

result:

ok 3 lines

Test #42:

score: 0
Accepted
time: 3ms
memory: 9420kb

input:

08f55b3f-c300-4051-a472-59ca2a776178
2
2 -2 -2 2

output:

9ce55564-5404-428a-8d2e-0d809c85101e
OK
1

result:

ok 3 lines

Test #43:

score: 0
Accepted
time: 0ms
memory: 9548kb

input:

08f55b3f-c300-4051-a472-59ca2a776178
2
1 1 -1 -1

output:

9ce55564-5404-428a-8d2e-0d809c85101e
OK
3

result:

ok 3 lines

Test #44:

score: 0
Accepted
time: 3ms
memory: 9300kb

input:

08f55b3f-c300-4051-a472-59ca2a776178
2
2 -2 2 -2

output:

9ce55564-5404-428a-8d2e-0d809c85101e
OK
2

result:

ok 3 lines

Test #45:

score: 0
Accepted
time: 0ms
memory: 9352kb

input:

08f55b3f-c300-4051-a472-59ca2a776178
2
1 1 -1 -1

output:

9ce55564-5404-428a-8d2e-0d809c85101e
OK
3

result:

ok 3 lines

Test #46:

score: 0
Accepted
time: 0ms
memory: 9276kb

input:

08f55b3f-c300-4051-a472-59ca2a776178
3
2 -2 -2 2 -2 2

output:

9ce55564-5404-428a-8d2e-0d809c85101e
OK
1

result:

ok 3 lines

Test #47:

score: -20
Wrong Answer
time: 0ms
memory: 9268kb

input:

08f55b3f-c300-4051-a472-59ca2a776178
8
-3 -3 -3 3 -3 -3 -3 3 3 3 3 3 3 3 -3 -3

output:

9ce55564-5404-428a-8d2e-0d809c85101e
OK
19

result:

wrong answer 3rd lines differ - expected: '15', found: '19'

Subtask #4:

score: 0
Wrong Answer

Test #74:

score: 15
Accepted
time: 0ms
memory: 9292kb

input:

08f55b3f-c300-4051-a472-59ca2a776178
1
-1 1

output:

9ce55564-5404-428a-8d2e-0d809c85101e
OK
0

result:

ok 3 lines

Test #75:

score: 0
Accepted
time: 3ms
memory: 9280kb

input:

08f55b3f-c300-4051-a472-59ca2a776178
2
-1 -2 1 2

output:

9ce55564-5404-428a-8d2e-0d809c85101e
OK
1

result:

ok 3 lines

Test #76:

score: 0
Accepted
time: 0ms
memory: 9424kb

input:

08f55b3f-c300-4051-a472-59ca2a776178
2
-2 -1 2 1

output:

9ce55564-5404-428a-8d2e-0d809c85101e
OK
1

result:

ok 3 lines

Test #77:

score: 0
Accepted
time: 3ms
memory: 9356kb

input:

08f55b3f-c300-4051-a472-59ca2a776178
2
-1 -1 1 1

output:

9ce55564-5404-428a-8d2e-0d809c85101e
OK
1

result:

ok 3 lines

Test #78:

score: -15
Wrong Answer
time: 107ms
memory: 22124kb

input:

08f55b3f-c300-4051-a472-59ca2a776178
99998
-93375 -85998 -57472 -57320 -92144 -31526 -99604 -77181 -65443 -97629 -29716 -1904 -93293 -41761 -55949 -50927 -80082 -21357 -51929 -54 -33477 -36300 -49484 -70830 -98314 -40123 -79568 -89806 -90528 -51711 -49394 -2023 -42435 -61625 -61156 -82943 -47590 -69...

output:

9ce55564-5404-428a-8d2e-0d809c85101e
OK
6909472766

result:

wrong answer 3rd lines differ - expected: '4999750003', found: '6909472766'

Subtask #5:

score: 0
Skipped

Dependency #2:

0%

Subtask #6:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

0%