QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#674081 | #8749. 贸易 | app1eDog# | WA | 52ms | 9684kb | C++20 | 2.7kb | 2024-10-25 13:41:39 | 2024-10-25 13:41:39 |
Judging History
answer
// created on Lucian Xu's Laptop
#include <bits/stdc++.h>
// using namespace std;
#define typet typename T
#define typeu typename U
#define types typename... Ts
#define tempt template <typet>
#define tempu template <typeu>
#define temps template <types>
#define tandu template <typet, typeu>
using UI = unsigned int;
using ULL = unsigned long long;
using LL = long long;
using ULL = unsigned long long;
using i128 = __int128;
using PII = std::pair<int, int>;
using PIL = std::pair<int, LL>;
using PLI = std::pair<LL, int>;
using PLL = std::pair<LL, LL>;
using vi = std::vector<int>;
using vvi = std::vector<vi>;
using vl = std::vector<LL>;
using vvl = std::vector<vl>;
using vpi = std::vector<PII>;
#define ff first
#define ss second
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) \
do { \
} while (false)
#endif
constexpr int mod = 998244353;
constexpr int inv2 = (mod + 1) / 2;
constexpr int inf = 0x3f3f3f3f;
constexpr LL INF = 1e18;
constexpr double pi = 3.141592653589793;
constexpr double eps = 1e-6;
constexpr int lowbit(int x) { return x & -x; }
tandu bool Max(T& x, const U& y) { return x < y ? x = y, true : false; }
tandu bool Min(T& x, const U& y) { return x > y ? x = y, true : false; }
void solut() {
int n, q;
std::cin >> n >> q;
vi a(n + 1), c(n + 1);
for (int i = 1; i <= n; i++) std::cin >> a[i];
for (int i = 1; i <= n; i++) std::cin >> c[i];
std::vector<vpi> qs(n + 1);
vi ans(q);
for (int i = 0, l, r; i < q; i++) {
std::cin >> l >> r;
qs[r].emplace_back(l, i);
}
vi tr(n + 1);
auto add = [&](int pos, int val) {
while (pos) {
tr[pos] += val;
pos -= lowbit(pos);
}
};
auto query = [&](int pos) {
int ans = 0;
while (pos <= n) {
ans += tr[pos];
pos += lowbit(pos);
}
return ans;
};
vvi v(n + 1);
for (int i = 1; i <= n; i++) {
if (a[i] == 0) {
v[c[i]].push_back(i);
} else {
if (v[c[i]].empty()) {
continue;
} else {
add(v[c[i]].back(), 1);
v[c[i]].pop_back();
}
}
for (const auto& [l, id] : qs[i]) {
ans[id] = query(l);
}
debug(tr);
}
for (const auto& x : ans) std::cout << x << '\n';
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(0);
std::cout.tie(0);
int t = 1;
// std::cin >> t;
while (t--) {
solut();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3476kb
input:
10 5 1 1 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 4 6 2 4 2 6 7 10 4 7
output:
0 0 0 1 0
result:
ok 5 lines
Test #2:
score: 0
Accepted
time: 52ms
memory: 9684kb
input:
20 500000 1 0 0 1 0 0 0 0 1 0 1 0 1 0 1 0 1 0 0 0 1 2 1 2 2 1 1 2 1 1 1 2 2 1 2 2 2 1 1 2 13 20 8 9 1 7 5 13 3 10 3 19 14 15 1 5 9 17 7 10 6 6 8 20 1 17 13 20 4 6 16 20 7 14 2 16 3 17 11 12 1 1 15 20 11 15 2 12 2 15 8 16 9 12 9 13 10 19 12 19 9 13 4 8 2 2 19 19 9 17 4 20 4 14 4 8 6 13 13 17 15 16 13...
output:
1 0 1 3 1 5 0 1 3 1 0 4 6 1 0 1 3 5 5 0 0 1 1 3 5 3 1 2 3 2 2 0 0 0 3 5 3 0 3 1 0 1 1 4 2 2 2 1 0 0 2 3 1 0 3 1 0 1 4 0 1 0 5 3 1 0 1 1 1 1 0 5 3 5 5 5 2 3 2 2 2 0 4 2 0 1 6 5 1 2 2 5 4 1 1 1 1 3 1 2 5 1 2 1 0 0 5 0 1 4 3 5 0 4 2 3 0 2 3 1 1 1 1 5 0 2 3 0 6 1 1 5 0 1 4 2 0 6 3 1 0 1 2 0 2 1 0 0 0 0 ...
result:
ok 500000 lines
Test #3:
score: -100
Wrong Answer
time: 52ms
memory: 9624kb
input:
30 500000 1 0 1 1 0 1 1 0 0 1 0 1 0 0 0 1 1 0 0 0 0 1 1 1 0 0 0 1 0 1 2 3 2 1 2 1 3 2 1 3 1 2 3 1 2 1 3 2 3 2 1 2 1 2 1 1 1 2 3 2 5 19 3 25 8 23 17 19 15 26 3 27 1 10 25 30 16 22 11 21 17 29 21 30 11 26 3 27 21 22 17 23 1 14 5 21 24 27 8 20 15 29 13 25 11 19 5 15 7 18 24 28 7 26 3 24 14 26 4 5 11 19...
output:
3 6 5 0 3 6 0 0 1 2 3 1 5 6 0 2 2 3 0 3 4 5 2 1 3 0 6 6 4 0 2 5 8 7 1 3 0 5 2 2 2 0 2 3 0 2 3 4 0 0 3 6 2 0 6 3 3 3 5 6 0 2 4 3 3 0 0 1 2 0 0 3 3 4 1 6 2 2 0 3 0 4 1 3 0 2 2 6 2 0 1 6 4 4 2 0 0 0 1 6 6 0 1 0 0 0 0 1 3 6 2 0 4 3 0 5 8 7 1 1 6 0 6 3 3 0 4 3 1 0 8 4 5 3 3 0 0 0 2 3 6 5 3 5 0 0 2 7 4 2 ...
result:
wrong answer 7th lines differ - expected: '1', found: '0'