Please can someone help me with this atcoder problem? I almost solved my first every problem D...

Правка en3, от comingsoon.cpp, 2024-03-02 23:17:12

Hello Guys.. I was trying to solve This atcoder problem From the last beginner contest but i was not able to come up with a working solution during the contest...After some upsolving, i finally came up with a solution that seems to work but the only problem is that it get's TLE on all the tests except the first three for which it passes and I don't know/understand why. This was the first ever ABC problem D that i have attempted after reading the problem statement.

This is the code below and I just need a little help or maybe come hints as to how to make it work because i can't think of a way to optimize it further.

#include <set>
#include <numeric>
#include <algorithm>
#include <vector>
#include <iostream>
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
using namespace std;

int check(vector<int> a){
	int q = a.size();
	set<int> s; for(int i = 0; i < q; i++){
		s.insert(a[i]);
	}
	return s.size();
}
void solve(){
	int n , t; cin >> n >> t;
	vector<int> mex; for(int i = 0; i < n; i++) mex.push_back(0);
	for(int i = 0; i < t; i++){
		int a, b; cin >> a >> b;
		mex[a-1] += b;
		cout << check(mex) << endl;
	}
}
int main (){
	ios::sync_with_stdio(false); 
	cin.tie(nullptr);
	//ll t; cin >> t;
	//for(;t--;){
		solve();
	//}
return 0;
}

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en3 Английский comingsoon.cpp 2024-03-02 23:17:12 3 Tiny change: 'w to make the work beca' -> 'w to make it work beca'
en2 Английский comingsoon.cpp 2024-03-02 23:15:56 12
en1 Английский comingsoon.cpp 2024-03-02 23:14:53 1463 Initial revision (published)