1 条题解

  • 0
    @ 2025-5-6 20:20:23

    将每一列的方块的行数和下标存起来,从小到大排序,对于消除操作,如果可以消除,一定是先同时消除每一列最底下的方块,再同时消除每一列自底向上第二个方块...,因此排序后只需要从下往上遍历每一列的每个方块,这些方块消失的时间就是他们之中最高的一个掉到底所需的时间,遍历一遍取maxmax即可,将每一个方块消失的时间存起来,处理查询即可。

    将数组所有位置初始化成正无穷,如果当前列的当前位置没有方块,同行的方块的最大值也就是正无穷,也就是他们会在第正无穷秒时消失,也就是不会消失。

    时间复杂度:O(n+q)O(n + q)

    #include <iostream>
    #include <algorithm>
    #include <vector>
    #define endl '\n'
    using namespace std;
    typedef pair<int, int> PII;
    
    int main(){
    	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    	int n, w;
    	cin >> n >> w;
    	vector<vector<PII>> v(w + 1);
    	for(int i = 1; i <= n; i++){
    		int x, y;
    		cin >> x >> y;
    		v[x].push_back({y, i});
    	}
    	for(int x = 1; x <= w; x++){
    		sort(v[x].begin(), v[x].end());
    	}
    	int minn = n;
    	for(int x = 1; x <= w; x++){
    		minn = min(minn, (int)v[x].size());
    	}
    	vector<int> res(n + 1, 2e9);
    	for(int y = 0; y < minn; y++){
    		int t = 0;
    		for(int x = 1; x <= w; x++){
    			t = max(t, v[x][y].first);
    		}
    		for(int x = 1; x <= w; x++){
    			res[v[x][y].second] = t;
    		}
    	}
    	int q;
    	cin >> q;
    	while(q--){
    		int t, x;
    		cin >> t >> x;
    		if(t < res[x]) cout << "Yes" << endl;
    		else cout << "No" << endl;
    	}
    	return 0;
    }
    
    • 1

    你有这个时间是不是能做两百道题

    信息

    ID
    2271
    时间
    1000ms
    内存
    256MiB
    难度
    9
    标签
    (无)
    递交数
    13
    已通过
    3
    上传者