답안 #964579

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
964579 2024-04-17T06:52:29 Z noobcodur Meteors (POI11_met) C++14
74 / 100
1179 ms 35956 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+2;

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);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2396 KB Output is correct
2 Correct 2 ms 2396 KB Output is correct
3 Correct 2 ms 2392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2396 KB Output is correct
2 Correct 3 ms 2636 KB Output is correct
3 Correct 3 ms 2648 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 66 ms 5396 KB Output is correct
2 Correct 150 ms 10648 KB Output is correct
3 Correct 95 ms 6604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 97 ms 6088 KB Output is correct
2 Correct 103 ms 6092 KB Output is correct
3 Correct 170 ms 10596 KB Output is correct
4 Correct 54 ms 5420 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 110 ms 5564 KB Output is correct
2 Correct 204 ms 10468 KB Output is correct
3 Correct 42 ms 4048 KB Output is correct
4 Correct 113 ms 7620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 42 ms 4752 KB Output is correct
2 Correct 121 ms 6172 KB Output is correct
3 Correct 63 ms 4816 KB Output is correct
4 Correct 160 ms 10692 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1179 ms 35956 KB Output is correct
2 Incorrect 716 ms 20172 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1068 ms 34180 KB Output is correct
2 Incorrect 687 ms 20772 KB Output isn't correct
3 Halted 0 ms 0 KB -