QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#245160 | #7661. Japanese Lottery | Yarema# | RE | 0ms | 3608kb | C++17 | 1.8kb | 2023-11-09 19:30:57 | 2023-11-09 19:30:58 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (a) - 1; i >= (b); i--)
#define SZ(a) int(a.size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second
typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef double db;
int f(const VI& p)
{
int cnt = 0;
int n = SZ(p);
VI used(n, 0);
FOR (i, 0, n)
{
if (!used[i])
{
int x = p[i];
used[i] = 1;
while (p[x] != p[i])
{
used[x] = 1;
cnt++;
x = p[x];
}
}
}
return cnt;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout << fixed << setprecision(15);
int n, h, q;
cin >> n >> h >> q;
vector<set<PII>> s(n);
FOR (i, 0, n)
{
s[i].insert({0, i});
s[i].insert({h, i});
}
VI p(n);
VI p2(n);
iota(ALL(p), 0);
iota(ALL(p2), 0);
FOR (i, 0, q)
{
int y, x1, x2;
cin >> y >> x1 >> x2;
x1--, x2--;
int idx1 = -1, idx2 = -1;
FOR (j, 0, n)
{
auto it = prev(s[j].upper_bound(MP(y, -1)));
if (it->S == x1)
idx1 = j;
if (it->S == x2)
idx2 = j;
}
//cerr << i << ": " << idx1 << ' ' << idx2 << '\n';
//FOR (k, 0, n)
// cerr << p[k] << ' ';
//cerr << "\n";
assert(idx1 != -1);
assert(idx2 != -1);
assert(idx1 != idx2);
swap(p[p2[idx1]], p[p2[idx2]]);
swap(p2[idx1], p2[idx2]);
//FOR (k, 0, n)
// cerr << p[k] << ' ';
//cerr << "\n\n";
FOR (t, 0, 2)
{
auto it = s[idx1].lower_bound(MP(y, -1));
if (it->F == y)
{
s[idx1].erase(it);
}
else
{
s[idx1].insert({y, x2});
}
swap(idx2, idx1);
swap(x1, x2);
}
cout << f(p) << '\n';
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3592kb
input:
4 6 7 1 1 2 2 3 4 4 3 4 5 1 2 6 3 4 3 2 3 6 3 4
output:
1 2 1 0 1 2 1
result:
ok 7 lines
Test #2:
score: 0
Accepted
time: 0ms
memory: 3608kb
input:
5 9 12 1 3 4 2 1 2 3 2 3 4 4 5 5 2 1 6 4 3 7 2 3 8 4 3 9 4 5 6 4 3 7 2 3 1 3 4
output:
1 2 3 4 3 2 3 4 3 4 3 2
result:
ok 12 lines
Test #3:
score: -100
Runtime Error
input:
20 60 200000 49 11 10 18 6 7 24 4 5 56 10 9 14 19 18 44 2 3 4 3 4 24 4 5 30 4 5 56 10 9 44 2 3 50 10 9 43 6 7 50 9 10 18 7 6 13 16 17 57 16 15 52 7 6 55 7 8 10 18 19 47 17 16 11 11 12 33 17 18 7 11 10 57 15 16 45 9 8 47 17 16 56 17 16 10 18 19 19 5 4 21 9 8 53 10 11 22 8 9 4 4 3 13 16 17 7 11 10 4 8...