Submission #900551

#TimeUsernameProblemLanguageResultExecution timeMemory
900551qinCell Automaton (JOI23_cell)C++17
16 / 100
346 ms48296 KiB
#include <bits/stdc++.h>
#define fi first
#define se second
#define ssize(x) int(x.size())
#define pn printf("\n");
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
int inf = 2e09; ll infll = 2e18; int mod = 119<<23|1;
struct st{
		int t, type; ll c;
		bool operator<(const st &x) const{ return t == x.t ? type < x.type : t < x.t; }
};
void answer(){
		int n, q; scanf("%d%d", &n, &q);
		vector<int> t(n);
		for(int i = 0; i < n; ++i){
				int x, y; scanf("%d%d", &x, &y);
				t[i] = x;
		}
		sort(t.begin(), t.end());
		vector<st> ev;
		vector<int> qr(q);
		for(int i = 0; i < q; ++i){
				int T; scanf("%d", &T); qr[i] = T;
				ev.push_back({T, 2, 0});
		}
		for(int i = 0; i < n-1; ++i){
				ev.push_back({t[i+1]-t[i], 0, t[i+1]-t[i]+1});
				ev.push_back({t[i+1]-t[i]+1, 1, t[i+1]-t[i]+3});
		}
		sort(ev.begin(), ev.end());
		unordered_map<int, ll> result;
		ll offset = 0, cnt = n;
		for(st u : ev){
				//~ printf("%d %d %lld\n", u.t, u.type, u.c);
				if(u.type == 2) result[u.t] = (ll(u.t)*4*cnt)-offset;
				else offset += u.c;
				if(u.type == 1) --cnt, offset -= 4ll*u.t;
		} result[0] = n;
		for(int i = 0; i < q; ++i) printf("%lld\n", result[qr[i]]);
}
signed main(){
		int T = 1;
		for(++T; --T; ) answer();
		return 0;
}

Compilation message (stderr)

cell.cpp: In function 'void answer()':
cell.cpp:15:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |   int n, q; scanf("%d%d", &n, &q);
      |             ~~~~~^~~~~~~~~~~~~~~~
cell.cpp:18:20: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |     int x, y; scanf("%d%d", &x, &y);
      |               ~~~~~^~~~~~~~~~~~~~~~
cell.cpp:25:17: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |     int T; scanf("%d", &T); qr[i] = T;
      |            ~~~~~^~~~~~~~~~
#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...