Submission #1041393

# Submission time Handle Problem Language Result Execution time Memory
1041393 2024-08-02T02:41:30 Z hungeazy Tram (CEOI13_tram) C++17
45 / 100
13 ms 4576 KB
/*
* @Author: hungeazy
* @Date:   2024-08-02 09:20:31
* @Last Modified by:   hungeazy
* @Last Modified time: 2024-08-02 09:41:09
*/
#include <bits/stdc++.h>
// #pragma GCC optimize("O3")  
// #pragma GCC optimize("unroll-loops")  
// #pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt")  
using namespace std;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define int long long
#define ull unsigned long long
#define sz(x) x.size()
#define sqr(x) (1LL * (x) * (x))
#define all(x) x.begin(), x.end()
#define fill(f,x) memset(f,x,sizeof(f))
#define FOR(i,l,r) for(int i=l;i<=r;i++)
#define FOD(i,r,l) for(int i=r;i>=l;i--)
#define ii pair<int,int>
#define iii pair<int,ii>
#define di pair<ii,ii>
#define vi vector<int>
#define vii vector<ii>
#define mii map<int,int>
#define fi first
#define se second
#define pb push_back
#define MOD 1000000007
#define __lcm(a,b) (1ll * ((a) / __gcd((a), (b))) * (b))
#define YES cout << "YES\n"
#define NO cout << "NO\n"
#define MASK(i) (1LL << (i))
#define c_bit(i) __builtin_popcountll(i)
#define BIT(x,i) ((x) & MASK(i))
#define SET_ON(x,i) ((x) | MASK(i))
#define SET_OFF(x,i) ((x) & ~MASK(i))
#define oo 1e18
#define name ""
#define endl '\n'
#define time() cerr << endl << "-------------Time:" << 1000.0 * clock() / CLOCKS_PER_SEC << "ms.";
template<typename T> bool maximize(T &res, const T &val) { if (res < val){ res = val; return true; }; return false; }
template<typename T> bool minimize(T &res, const T &val) { if (res > val){ res = val; return true; }; return false; }
const int N = (int)1e6+10;
int n,q;

namespace sub12 {

	int sz = 0,d[N][2];
	ii save[N];
	bool check[N][2];

	int DIST(ii a, ii b)
	{
		return sqr(a.fi-b.fi)+sqr(a.se-b.se);
	}

	ii calc()
	{
		if (!sz) return {1,0};
		FOR(i,1,n)
			FOR(j,0,1) d[i][j] = oo;
		ii pos = {0,0};
		FOR(i,1,n)
		{
			FOR(j,0,1)
				if (!check[i][j])
				{
					if (pos.fi != 0) d[i][j] = min(d[i][j],DIST({i,j},{pos.fi,0}));
					if (pos.se != 0) d[i][j] = min(d[i][j],DIST({i,j},{pos.se,1}));
					if (check[i][j^1]) d[i][j] = 1;
				}
			if (check[i][0]) pos.fi = i;
			if (check[i][1]) pos.se = i; 
		}
		pos = {0,0};
		int ans = -oo;
		FOD(i,n,1)
		{
			FOR(j,0,1)
				if (!check[i][j])
				{
					if (pos.fi != 0) d[i][j] = min(d[i][j],DIST({i,j},{pos.fi,0}));
					if (pos.se != 0) d[i][j] = min(d[i][j],DIST({i,j},{pos.se,1}));
					maximize(ans,d[i][j]);
				}
			if (check[i][0]) pos.fi = i;
			if (check[i][1]) pos.se = i; 
		}
		FOR(i,1,n)
			FOR(j,0,1)
				if (!check[i][j] and ans == d[i][j]) return {i,j};
	}

	void solve(void)
	{
		int pos = 0;
		while (q--)
		{
			char type;
			cin >> type;
			if (type == 'E')
			{
				++pos;
				save[pos] = calc();
				check[save[pos].fi][save[pos].se] = true;
				cout << save[pos].fi << " " << save[pos].se+1 << endl;
				++sz;
			}
			else 
			{
				int x;
				cin >> x;
				++pos;
				check[save[x].fi][save[x].se] = false;
				--sz;
			}
		}
	}	
	
}

signed main()
{
    fast;
    if (fopen(name".inp","r"))
    {
    	freopen(name".inp","r",stdin);
    	freopen(name".out","w",stdout);
    }
    cin >> n >> q;
    if (n <= 2e3 and q <= 2e3) sub12::solve();
    time();
    return 0;
}
// ██░ ██  █    ██  ███▄    █   ▄████
//▓██░ ██▒ ██  ▓██▒ ██ ▀█   █  ██▒ ▀█▒
//▒██▀▀██░▓██  ▒██░▓██  ▀█ ██▒▒██░▄▄▄░
//░▓█ ░██ ▓▓█  ░██░▓██▒  ▐▌██▒░▓█  ██▓
//░▓█▒░██▓▒▒█████▓ ▒██░   ▓██░░▒▓███▀▒
// ▒ ░░▒░▒░▒▓▒ ▒ ▒ ░ ▒░   ▒ ▒  ░▒   ▒
// ▒ ░▒░ ░░░▒░ ░ ░ ░ ░░   ░ ▒░  ░   ░
// ░  ░░ ░ ░░░ ░ ░    ░   ░ ░ ░ ░   ░
// ░  ░  ░   ░              ░       ░

Compilation message

tram.cpp: In function 'std::pair<long long int, long long int> sub12::calc()':
tram.cpp:94:2: warning: control reaches end of non-void function [-Wreturn-type]
   94 |  }
      |  ^
tram.cpp: In function 'int main()':
tram.cpp:129:13: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  129 |      freopen(name".inp","r",stdin);
      |      ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
tram.cpp:130:13: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  130 |      freopen(name".out","w",stdout);
      |      ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 0 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 4444 KB Output is correct
2 Correct 1 ms 4564 KB Output is correct
3 Correct 8 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 4576 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 7 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -