Submission #964576

# Submission time Handle Problem Language Result Execution time Memory
964576 2024-04-17T06:49:39 Z noobcodur Meteors (POI11_met) C++14
74 / 100
1129 ms 36792 KB
#include<bits/stdc++.h>
using namespace std;

using ld = long double;

#define int long long
#define pii pair<int,int>
#define forn(i,j) for(int i = 0; i < j; ++i)
#define forrange(i,j,k) for(int i = j; i < k; ++i)
#define vi vector<int>
#define vpii vector<pii>
#define f first
#define s second
#define pb push_back
#define all(x) x.begin(),x.end()

const int MOD = 1e9+7; const int INF = 1e17+1; const int maxN = 3e5+1;

void setIO(string name){
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	if(!name.empty()){
		freopen((name + ".in").c_str(),"r",stdin);
		freopen((name + ".out").c_str(),"w",stdout);
	}
}

int bit[maxN];

void update(int idx, int val){
	while(idx < maxN){
		bit[idx] += val;
		idx += idx&-idx;
	}
}

int query(int idx){
	int res = 0;

	while(idx > 0){
		res += bit[idx];
		idx -= idx&-idx;
	}

	return res;
}

struct Query{
	int t,left,right,val;
};

struct Station{
	int lo,mid,hi,idx;
};

bool comp(Station A, Station B){
	return A.mid < B.mid;
}

int res[maxN];

signed main(){
	setIO("");
	int n,m; cin >> n >> m;
	vector<vi> loc(n+1);
	vi p(n+1);

	forrange(i,1,m+1){
		int a; cin >> a;
		loc[a].pb(i);
	}

	forrange(i,1,n+1){
		cin >> p[i];
	}

	int q; cin >> q;

	vector<Query> Q;

	forn(i,q){
		Query T;

		cin >> T.left >> T.right >> T.val;
		T.t = 0;

		if(T.left > T.right){
			T.t = 1;
			swap(T.left,T.right);
		} 

		Q.pb(T);
	}

	vector<Station> S;

	forrange(i,1,n+1){
		Station T;
		T.lo = 0, T.hi = q;
		T.mid = (T.lo + T.hi)/2;
		T.idx = i;

		S.pb(T);
	}

	while(!S.empty()){
		int ptr = -1;
		vector<Station> curr;

		for(Station T : S){
			if(T.lo >= T.hi){
				res[T.idx] = T.lo;
				continue;
			}

			while(ptr < q-1 && ptr < T.mid){
				ptr++;

				if(!Q[ptr].t){
					update(Q[ptr].left,Q[ptr].val);
					update(Q[ptr].right+1,-Q[ptr].val);
				}

				else{
					update(1,Q[ptr].val);
					update(Q[ptr].left+1,-Q[ptr].val);
					update(Q[ptr].right,Q[ptr].val);
				}
			}

			int ans = 0;

			for(int j : loc[T.idx]){
				ans += query(j);
			}

			if(ans >= p[T.idx]){
				T.hi = T.mid;
				T.mid = (T.lo + T.hi)/2;

				curr.pb(T);
			}

			else{
				T.lo = T.mid+1;
				T.mid = (T.lo + T.hi)/2;
				curr.pb(T);
			}
		}

		S.clear();
		sort(all(curr),comp);
		fill(bit,bit+m+1,0);

		for(Station T : curr) S.pb(T);
	}


	forrange(i,1,n+1){
		if(res[i] == q){
			cout << "NIE" << endl; 
		}

		else cout << res[i]+1 << endl;
	}
}

Compilation message

met.cpp: In function 'void setIO(std::string)':
met.cpp:24:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |   freopen((name + ".in").c_str(),"r",stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
met.cpp:25:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |   freopen((name + ".out").c_str(),"w",stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2392 KB Output is correct
2 Correct 3 ms 2392 KB Output is correct
3 Correct 2 ms 2392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2624 KB Output is correct
2 Correct 3 ms 2624 KB Output is correct
3 Correct 3 ms 2904 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 63 ms 5356 KB Output is correct
2 Correct 162 ms 10572 KB Output is correct
3 Correct 97 ms 6768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 103 ms 6136 KB Output is correct
2 Correct 115 ms 6416 KB Output is correct
3 Correct 163 ms 10652 KB Output is correct
4 Correct 52 ms 5396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 108 ms 5504 KB Output is correct
2 Correct 226 ms 10544 KB Output is correct
3 Correct 49 ms 4052 KB Output is correct
4 Correct 144 ms 7664 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 43 ms 4688 KB Output is correct
2 Correct 120 ms 6248 KB Output is correct
3 Correct 64 ms 4816 KB Output is correct
4 Correct 145 ms 10712 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1129 ms 35620 KB Output is correct
2 Incorrect 689 ms 19916 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1106 ms 36792 KB Output is correct
2 Incorrect 484 ms 20808 KB Output isn't correct
3 Halted 0 ms 0 KB -