제출 #443238

#제출 시각아이디문제언어결과실행 시간메모리
443238gs12117새로운 문제 (POI11_met)C++14
100 / 100
3397 ms65536 KiB
#include<cstdio>
#include<vector>
int n, m, q;
int o[300100];
std::vector<int> owned_stn[300100];
long long int p[300100];
int l[300100];
int r[300100];
long long int a[300100];
int ans[300100];
std::vector<int> check_for_q[300100];
const long long int itsz = 1 << 19;
long long int it[2 * itsz];
void itpush(int s, int e, long long int v) {
	s += itsz;
	e += itsz;
	while (s <= e) {
		if (s % 2 == 1) {
			it[s] += v;
			s++;
		}
		if (e % 2 == 0) {
			it[e] += v;
			e--;
		}
		s /= 2;
		e /= 2;
	}
}
long long int itcalc(int x) {
	x += itsz;
	long long int res = 0;
	while (x > 0) {
		res += it[x];
		x /= 2;
	}
	return res;
}
void para_chk(int x, int parav) {
	long long int sum = 0;
	for (int i = 0; i < owned_stn[x].size(); i++) {
		sum += itcalc(owned_stn[x][i]);
		if (sum >= p[x])break;
	}
	if (p[x] <= sum)ans[x] -= parav;
}
void para(int parav) {
	for (int i = 0; i <= q + 3; i++) {
		check_for_q[i].clear();
	}
	for (int i = 1; i <= n; i++) {
		ans[i] += parav;
		if (ans[i] > q)ans[i] -= parav;
		else check_for_q[ans[i]].push_back(i);
	}
	for (int i = 0; i < 2 * itsz; i++) {
		it[i] = 0;
	}
	for (int i = 1; i <= q; i++) {
		if (l[i] <= r[i]) {
			itpush(l[i], r[i], a[i]);
		}
		else {
			itpush(l[i], m, a[i]);
			itpush(1, r[i], a[i]);
		}
		for (int j = 0; j < check_for_q[i].size(); j++) {
			int x = check_for_q[i][j];
			para_chk(x, parav);
		}
	}
}
int main() {
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= m; i++) {
		scanf("%d", &o[i]);
		owned_stn[o[i]].push_back(i);
	}
	for (int i = 1; i <= n; i++) {
		scanf("%lld", &p[i]);
	}
	scanf("%d", &q);
	for (int i = 1; i <= q; i++) {
		scanf("%d%d%lld", &l[i], &r[i], &a[i]);
	}
	for (int i = 18; i >= 0; i--) {
		para(1 << i);
	}
	for (int i = 1; i <= n; i++) {
		if (ans[i] >= q) {
			printf("NIE\n");
		}
		else {
			printf("%d\n", ans[i] + 1);
		}
	}
	return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

met.cpp: In function 'void para_chk(int, int)':
met.cpp:41:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |  for (int i = 0; i < owned_stn[x].size(); i++) {
      |                  ~~^~~~~~~~~~~~~~~~~~~~~
met.cpp: In function 'void para(int)':
met.cpp:67:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   67 |   for (int j = 0; j < check_for_q[i].size(); j++) {
      |                   ~~^~~~~~~~~~~~~~~~~~~~~~~
met.cpp: In function 'int main()':
met.cpp:74:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   74 |  scanf("%d%d", &n, &m);
      |  ~~~~~^~~~~~~~~~~~~~~~
met.cpp:76:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   76 |   scanf("%d", &o[i]);
      |   ~~~~~^~~~~~~~~~~~~
met.cpp:80:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   80 |   scanf("%lld", &p[i]);
      |   ~~~~~^~~~~~~~~~~~~~~
met.cpp:82:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   82 |  scanf("%d", &q);
      |  ~~~~~^~~~~~~~~~
met.cpp:84:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   84 |   scanf("%d%d%lld", &l[i], &r[i], &a[i]);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...