Submission #62275756


Source Code Expand

Copy
#include <iostream> //
#include <algorithm> //
#include <vector> //
#include <queue> //
#include <stack> //
#include <set> //
#include <map> //
#include <list> //
#include <math.h> //
#include <functional> //
#define endl '\n'
#define pii pair<int, int>
#define pdd pair<double, double>
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define int long long
using namespace std;
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#include <iostream>		// 基本输入输出流
#include <algorithm>	// 通用算法(排序、查找、去重、二分查找等)
#include <vector>		// 动态数组(空间不够会自动扩容)
#include <queue>		// 队列(先进先出)
#include <stack>		// 栈(先进后出)
#include <set>			// 集合(有序不重复)
#include <map>			// 键值对容器(映射)
#include <list>			// 双向链表
#include <math.h>		// 数学函数
#include <functional>	// 通用的函数绑定和调用机制

#define endl '\n'
#define pii pair<int, int>
#define pdd pair<double, double>
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define int long long
using namespace std;

const int inf = 1e9 + 7;
const int mod = 998244353;
const int N = 2e5 + 10, M = N << 1;
void solve() {
    int n, q;
    cin >> n >> q;

    // 初始化鸽子和巢的状态
    vector<int> p(n + 1);  // p[i] 表示鸽子 i 所在的巢
    vector<int> nst(n + 1, 1); // nst[i] 表示巢 i 中有多少只鸽子
    for (int i = 1; i <= n; i++) {
        p[i] = i;          // 初始时鸽子 i 在巢 i 中
    }

    // 维护有多个鸽子的巢的数量
    int mon = 0;

    while (q--) {
        int t;
        cin >> t;

        if (t == 1) {
            int pp, h;
            cin >> pp >> h;

            int old_nest = p[pp];
            if (--nst[old_nest] == 1) {
                mon--;
            }
            if (++nst[h] == 2) {
                mon++;
            }
            p[pp] = h;
        } else {
            cout << mon << endl;
        }
    }
}

signed main(){
	//重定向输入输出
//    freopen("pow.in", "r", stdin);
//    freopen("pow.out", "w", stdout);

    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    int _ = 1;
//	cin >> _;	// 非多组测试数据请注释该行
    while(_--) solve();
    return 0;
}

Submission Info

Submission Time
Task C - Pigeonhole Query
User Digital_Enigma
Language C++ 20 (gcc 12.2)
Score 300
Code Size 1952 Byte
Status AC
Exec Time 105 ms
Memory 18712 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 300 / 300
Status
AC × 2
AC × 39
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt
All 00_sample_00.txt, 00_sample_01.txt, 01_test_00.txt, 01_test_01.txt, 01_test_02.txt, 01_test_03.txt, 01_test_04.txt, 01_test_05.txt, 01_test_06.txt, 01_test_07.txt, 01_test_08.txt, 01_test_09.txt, 01_test_10.txt, 01_test_11.txt, 01_test_12.txt, 01_test_13.txt, 01_test_14.txt, 01_test_15.txt, 01_test_16.txt, 01_test_17.txt, 01_test_18.txt, 01_test_19.txt, 01_test_20.txt, 01_test_21.txt, 01_test_22.txt, 01_test_23.txt, 01_test_24.txt, 01_test_25.txt, 01_test_26.txt, 01_test_27.txt, 01_test_28.txt, 01_test_29.txt, 01_test_30.txt, 01_test_31.txt, 01_test_32.txt, 01_test_33.txt, 01_test_34.txt, 01_test_35.txt, 01_test_36.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 1 ms 3600 KB
00_sample_01.txt AC 1 ms 3456 KB
01_test_00.txt AC 1 ms 3380 KB
01_test_01.txt AC 1 ms 3404 KB
01_test_02.txt AC 1 ms 3404 KB
01_test_03.txt AC 2 ms 3544 KB
01_test_04.txt AC 14 ms 4624 KB
01_test_05.txt AC 24 ms 3488 KB
01_test_06.txt AC 18 ms 3624 KB
01_test_07.txt AC 25 ms 18616 KB
01_test_08.txt AC 20 ms 3456 KB
01_test_09.txt AC 36 ms 18572 KB
01_test_10.txt AC 22 ms 3408 KB
01_test_11.txt AC 43 ms 18624 KB
01_test_12.txt AC 23 ms 3432 KB
01_test_13.txt AC 52 ms 18576 KB
01_test_14.txt AC 24 ms 3496 KB
01_test_15.txt AC 60 ms 18660 KB
01_test_16.txt AC 26 ms 3484 KB
01_test_17.txt AC 69 ms 18564 KB
01_test_18.txt AC 26 ms 3432 KB
01_test_19.txt AC 75 ms 18664 KB
01_test_20.txt AC 27 ms 3492 KB
01_test_21.txt AC 82 ms 18488 KB
01_test_22.txt AC 27 ms 3344 KB
01_test_23.txt AC 91 ms 18644 KB
01_test_24.txt AC 28 ms 3456 KB
01_test_25.txt AC 99 ms 18564 KB
01_test_26.txt AC 29 ms 3436 KB
01_test_27.txt AC 105 ms 18644 KB
01_test_28.txt AC 24 ms 3436 KB
01_test_29.txt AC 67 ms 18712 KB
01_test_30.txt AC 24 ms 3540 KB
01_test_31.txt AC 67 ms 18648 KB
01_test_32.txt AC 23 ms 3416 KB
01_test_33.txt AC 66 ms 18576 KB
01_test_34.txt AC 67 ms 18616 KB
01_test_35.txt AC 64 ms 18580 KB
01_test_36.txt AC 48 ms 18648 KB


2025-03-23 (Sun)
11:41:30 +00:00