submission_id stringlengths 10 10 | problem_id stringlengths 6 6 | language stringclasses 3 values | code stringlengths 1 522k | compiler_output stringlengths 43 10.2k |
|---|---|---|---|---|
s480889577 | p03800 | C++ | #include<iostream>
#include<queue>
#include<bitset>
#include<algorithm>
#include<climits>
#include<vector>
#include<deque>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define fill(x,y) memset(x,y,sizeof(x))
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define dump(a) rep(i,a.size()){ cout<<a[i]<<" "; } cout<<endl;
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define INF INT_MAX/3
#define EPS 1e-7
void print(int n, bool t[n]){
rep(i,n){
if(t[i]) cout<<'S';
else cout<<'W';
}
cout<<endl;
}
int main(){
ll n;
cin>>n;
string s;
cin>>s;
bool t[100001]; // t[i] i番目が本物ならtrue
/* cout<<((1==1)?"True":"False"); */
rep(i0,2) rep(i1,2) {
// i0=0, i1=0を仮定する
t[0]=i0; t[1]=i1;
/* cout<<"初期値"<<t[0]<<t[1]<<endl; */
repl(i,1,n-1){
if(s[i]=='o')
t[i+1] = (t[i]) ? t[i-1] : !t[i-1];
else
t[i+1] = (t[i]) ? !t[i-1] : t[i-1];
/* cout<<i+1<<"は"<<t[i+1]<<endl; */
}
if(s[n-1]=='o') {
bool f = (t[n-1]) ? t[n-2] : !t[n-2];
if(f==t[0]){
/* cout<<i0<<i1<<endl; */
print(n,t);
return 0;
}
} else {
bool f = (t[n-1]) ? !t[n-2] : t[n-2];
if(f==t[0]){
/* cout<<i0<<i1<<endl; */
print(n,t);
return 0;
}
}
}
cout<<"-1"<<endl;
return 0;
}
| a.cc:24:27: error: use of parameter outside function body before ']' token
24 | void print(int n, bool t[n]){
| ^
a.cc: In function 'void print(...)':
a.cc:25:9: error: 'n' was not declared in this scope
25 | rep(i,n){
| ^
a.cc:12:45: note: in definition of macro 'repl'
12 | #define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
| ^
a.cc:25:3: note: in expansion of macro 'rep'
25 | rep(i,n){
| ^~~
a.cc:26:8: error: 't' was not declared in this scope
26 | if(t[i]) cout<<'S';
| ^
|
s472648815 | p03800 | C++ | #include <cstdio>
using namespace std;
int main() {
int n;
char s[100010], sw[100010];
scanf("%d", &n);
scanf("%100005s", s);
for (int i=0;i<4;i++) {
sw[0] = (i/2 == 0)?'S':'W';
sw[1] = (i%2 == 0)?'S':'W';
for (int j=2;j<n;j++) {
if ((sw[j-1] == 'S') == (s[j-1] == 'o')) {
sw[j] = sw[j-2];
} else {
sw[j] = ((sw[j-2]=='S')?'W':'S');
}
}
bool valid = true;
if ((sw[n-1] == 'S') == (s[n-1] == 'o'))
if (sw[n-2] != sw[0]) valid = false
else
if (sw[n-2] == sw[0]) valid = false
if ((sw[0] == 'S') == (s[0] == 'o'))
if (sw[n-1] != sw[1]) valid = false
else
if (sw[n-1] == sw[1]) valid = false
if (valid) {
printf("%s\n", sw);
return 0;
}
}
printf("-1\n");
return 0;
}
| a.cc: In function 'int main()':
a.cc:26:42: error: expected ';' before 'else'
26 | if (sw[n-2] != sw[0]) valid = false
| ^
| ;
27 | else
| ~~~~
|
s763164631 | p03800 | C++ | import java.io.*;
import java.util.*;
/**
* @author baito
*/
public class Main
{
static StringBuilder sb = new StringBuilder();
static FastScanner sc = new FastScanner(System.in);
static int INF = 12345678;
static long LINF = 123456789123456789L;
static long MINF = -123456789123456789L;
static long MOD = 1000000007;
static int[] y4 = {0, 1, 0, -1};
static int[] x4 = {1, 0, -1, 0};
static int[] y8 = {0, 1, 0, -1, -1, 1, 1, -1};
static int[] x8 = {1, 0, -1, 0, 1, -1, 1, -1};
static long[] F;//factorial
static boolean[] isPrime;
static int[] primes;
static char[][] map;
static int N;
static char[]s;
public static void main(String[] args)
{
N =sc.nextInt();
s = sc.next().toCharArray();
int[] test = new int[N];
//ss s 1 w -1
test[0] = 1;
test[1] = 1;
if(can(test)){
pint(test);
return ;
}
//sw
Arrays.fill(test,0);
test[0] = 1;
test[1] = -1;
if(can(test)){
pint(test);
return ;
}
//ws
Arrays.fill(test,0);
test[0] = -1;
test[1] = 1;
if(can(test)){
pint(test);
return ;
}
//ww
Arrays.fill(test,0);
test[0] = -1;
test[1] = -1;
if(can(test)){
pint(test);
return ;
}
System.out.println("-1");
}
public void print(int[] res){
for(int i = 0 ; i < N; i++){
if(res[i] == 1){
System.out.println();
}
}
}
public static boolean can(int[] tes){
for(int i = 2; i < N - 1; i++){
if(s[i] == 'o'){
tes[i + 1] = tes[i - 1];
}else{
tes[i + 1] = tes[i - 1] *= -1;
}
}
if(tes[N - 1] == 'o'){
if(tes[N - 2] == tes[0] * tes[N-1])return true;
}else{
if(tes[N - 2] == tes[0] * tes[N-1] * -1)return true;
}
return false;
}
public static long toLong(int[] ar)
{
long res = 0;
for (int i : ar)
{
res *= 10;
res += i;
}
return res;
}
public static int toInt(int[] ar)
{
int res = 0;
for (int i : ar)
{
res *= 10;
res += i;
}
return res;
}
//k個の次の組み合わせをビットで返す 大きさに上限はない 110110 -> 111001
public static int nextCombSizeK(int comb, int k)
{
int x = comb & -comb; //最下位の1
int y = comb + x; //連続した下の1を繰り上がらせる
return ((comb & ~y) / x >> 1) | y;
}
public static int keta(long num)
{
int res = 0;
while (num > 0)
{
num /= 10;
res++;
}
return res;
}
public static long getHashKey(int a, int b)
{
return (long) a << 32 | b;
}
public static boolean isOutofIndex(int x, int y)
{
if (x < 0 || y < 0) return true;
if (map[0].length <= x || map.length <= y) return true;
return false;
}
public static void setPrimes()
{
int n = 100001;
isPrime = new boolean[n];
List<Integer> prs = new ArrayList<>();
Arrays.fill(isPrime, true);
isPrime[0] = isPrime[1] = false;
for (int i = 2; i * i <= n; i++)
{
if (!isPrime[i]) continue;
prs.add(i);
for (int j = i * 2; j < n; j += i)
{
isPrime[j] = false;
}
}
primes = new int[prs.size()];
for (int i = 0; i < prs.size(); i++)
primes[i] = prs.get(i);
}
public static void revSort(int[] a)
{
Arrays.sort(a);
reverse(a);
}
public static void revSort(long[] a)
{
Arrays.sort(a);
reverse(a);
}
public static int[][] copy(int[][] ar)
{
int[][] nr = new int[ar.length][ar[0].length];
for (int i = 0; i < ar.length; i++)
for (int j = 0; j < ar[0].length; j++)
nr[i][j] = ar[i][j];
return nr;
}
/**
* <h1>指定した値以上の先頭のインデクスを返す</h1>
* <p>配列要素が0のときは、0が返る。</p>
*
* @return<b>int</b> : 探索した値以上で、先頭になるインデクス
* 値が無ければ、挿入できる最小のインデックス
*/
public static int lowerBound(final int[] arr, final int value)
{
int low = 0;
int high = arr.length;
int mid;
while (low < high)
{
mid = ((high - low) >>> 1) + low; //(low + high) / 2 (オーバーフロー対策)
if (arr[mid] < value)
{
low = mid + 1;
}
else
{
high = mid;
}
}
return low;
}
/**
* <h1>指定した値より大きい先頭のインデクスを返す</h1>
* <p>配列要素が0のときは、0が返る。</p>
*
* @return<b>int</b> : 探索した値より上で、先頭になるインデクス
* 値が無ければ、挿入できる最小のインデックス
*/
public static int upperBound(final int[] arr, final int value)
{
int low = 0;
int high = arr.length;
int mid;
while (low < high)
{
mid = ((high - low) >>> 1) + low; //(low + high) / 2 (オーバーフロー対策)
if (arr[mid] <= value)
{
low = mid + 1;
}
else
{
high = mid;
}
}
return low;
}
/**
* <h1>指定した値以上の先頭のインデクスを返す</h1>
* <p>配列要素が0のときは、0が返る。</p>
*
* @return<b>int</b> : 探索した値以上で、先頭になるインデクス
* 値がなければ挿入できる最小のインデックス
*/
public static long lowerBound(final long[] arr, final long value)
{
int low = 0;
int high = arr.length;
int mid;
while (low < high)
{
mid = ((high - low) >>> 1) + low; //(low + high) / 2 (オーバーフロー対策)
if (arr[mid] < value)
{
low = mid + 1;
}
else
{
high = mid;
}
}
return low;
}
/**
* <h1>指定した値より大きい先頭のインデクスを返す</h1>
* <p>配列要素が0のときは、0が返る。</p>
*
* @return<b>int</b> : 探索した値より上で、先頭になるインデクス
* 値がなければ挿入できる最小のインデックス
*/
public static long upperBound(final long[] arr, final long value)
{
int low = 0;
int high = arr.length;
int mid;
while (low < high)
{
mid = ((high - low) >>> 1) + low; //(low + high) / 2 (オーバーフロー対策)
if (arr[mid] <= value)
{
low = mid + 1;
}
else
{
high = mid;
}
}
return low;
}
//次の順列に書き換える、最大値ならfalseを返す
public static boolean nextPermutation(int A[])
{
int len = A.length;
int pos = len - 2;
for (; pos >= 0; pos--)
{
if (A[pos] < A[pos + 1]) break;
}
if (pos == -1) return false;
//posより大きい最小の数を二分探索
int ok = pos + 1;
int ng = len;
while (Math.abs(ng - ok) > 1)
{
int mid = (ok + ng) / 2;
if (A[mid] > A[pos]) ok = mid;
else ng = mid;
}
swap(A, pos, ok);
reverse(A, pos + 1, len - 1);
return true;
}
//次の順列に書き換える、最小値ならfalseを返す
public static boolean prevPermutation(int A[])
{
int len = A.length;
int pos = len - 2;
for (; pos >= 0; pos--)
{
if (A[pos] > A[pos + 1]) break;
}
if (pos == -1) return false;
//posより小さい最大の数を二分探索
int ok = pos + 1;
int ng = len;
while (Math.abs(ng - ok) > 1)
{
int mid = (ok + ng) / 2;
if (A[mid] < A[pos]) ok = mid;
else ng = mid;
}
swap(A, pos, ok);
reverse(A, pos + 1, len - 1);
return true;
}
//↓nCrをmod計算するために必要。 ***factorial(N)を呼ぶ必要がある***
static long ncr(int n, int r)
{
if (n < r) return 0;
else if (r == 0) return 1;
factorial(n);
return F[n] / (F[n - r] * F[r]);
}
static long ncr2(int a, int b)
{
if (b == 0) return 1;
else if (a < b) return 0;
long res = 1;
for (int i = 0; i < b; i++)
{
res *= a - i;
res /= i + 1;
}
return res;
}
static long ncrdp(int n, int r)
{
if (n < r) return 0;
long[][] dp = new long[n + 1][r + 1];
for (int ni = 0; ni < n + 1; ni++)
{
dp[ni][0] = dp[ni][ni] = 1;
for (int ri = 1; ri < ni; ri++)
{
dp[ni][ri] = dp[ni - 1][ri - 1] + dp[ni - 1][ri];
}
}
return dp[n][r];
}
static long modNcr(int n, int r)
{
if (n < r) return 0;
long result = F[n];
result = result * modInv(F[n - r]) % MOD;
result = result * modInv(F[r]) % MOD;
return result;
}
public static long modSum(long... lar)
{
long res = 0;
for (long l : lar)
res = (res + l % MOD) % MOD;
return res;
}
public static long modDiff(long a, long b)
{
long res = a - b;
if (res < 0) res += MOD;
res %= MOD;
return res;
}
public static long modMul(long... lar)
{
long res = 1;
for (long l : lar)
res = (res * l) % MOD;
if (res < 0) res += MOD;
res %= MOD;
return res;
}
public static long modDiv(long a, long b)
{
long x = a % MOD;
long y = b % MOD;
long res = (x * modInv(y)) % MOD;
return res;
}
static long modInv(long n)
{
return modPow(n, MOD - 2);
}
static void factorial(int n)
{
F = new long[n + 1];
F[0] = F[1] = 1;
// for (int i = 2; i <= n; i++)
// {
// F[i] = (F[i - 1] * i) % MOD;
// }
//
for (int i = 2; i <= 100000; i++)
{
F[i] = (F[i - 1] * i) % MOD;
}
for (int i = 100001; i <= n; i++)
{
F[i] = (F[i - 1] * i) % MOD;
}
}
static long modPow(long x, long n)
{
long res = 1L;
while (n > 0)
{
if ((n & 1) == 1)
{
res = res * x % MOD;
}
x = x * x % MOD;
n >>= 1;
}
return res;
}
//↑nCrをmod計算するために必要
static int gcd(int n, int r)
{
return r == 0 ? n : gcd(r, n % r);
}
static long gcd(long n, long r)
{
return r == 0 ? n : gcd(r, n % r);
}
static <T> void swap(T[] x, int i, int j)
{
T t = x[i];
x[i] = x[j];
x[j] = t;
}
static void swap(int[] x, int i, int j)
{
int t = x[i];
x[i] = x[j];
x[j] = t;
}
public static void reverse(int[] x)
{
int l = 0;
int r = x.length - 1;
while (l < r)
{
int temp = x[l];
x[l] = x[r];
x[r] = temp;
l++;
r--;
}
}
public static void reverse(long[] x)
{
int l = 0;
int r = x.length - 1;
while (l < r)
{
long temp = x[l];
x[l] = x[r];
x[r] = temp;
l++;
r--;
}
}
public static void reverse(int[] x, int s, int e)
{
int l = s;
int r = e;
while (l < r)
{
int temp = x[l];
x[l] = x[r];
x[r] = temp;
l++;
r--;
}
}
static int length(int a)
{
int cou = 0;
while (a != 0)
{
a /= 10;
cou++;
}
return cou;
}
static int length(long a)
{
int cou = 0;
while (a != 0)
{
a /= 10;
cou++;
}
return cou;
}
static int cou(boolean[] a)
{
int res = 0;
for (boolean b : a)
{
if (b) res++;
}
return res;
}
static int cou(String s, char c)
{
int res = 0;
for (char ci : s.toCharArray())
{
if (ci == c) res++;
}
return res;
}
static int countC2(char[][] a, char c)
{
int co = 0;
for (int i = 0; i < a.length; i++)
for (int j = 0; j < a[0].length; j++)
if (a[i][j] == c) co++;
return co;
}
static int countI(int[] a, int key)
{
int co = 0;
for (int i = 0; i < a.length; i++)
if (a[i] == key) co++;
return co;
}
static int countI(int[][] a, int key)
{
int co = 0;
for (int i = 0; i < a.length; i++)
for (int j = 0; j < a[0].length; j++)
if (a[i][j] == key) co++;
return co;
}
static void fill(int[][] a, int v)
{
for (int i = 0; i < a.length; i++)
for (int j = 0; j < a[0].length; j++)
a[i][j] = v;
}
static void fill(long[][] a, long v)
{
for (int i = 0; i < a.length; i++)
for (int j = 0; j < a[0].length; j++)
a[i][j] = v;
}
static void fill(int[][][] a, int v)
{
for (int i = 0; i < a.length; i++)
for (int j = 0; j < a[0].length; j++)
for (int k = 0; k < a[0][0].length; k++)
a[i][j][k] = v;
}
static int max(int... a)
{
int res = Integer.MIN_VALUE;
for (int i : a)
{
res = Math.max(res, i);
}
return res;
}
static int max(int[][] ar)
{
int res = Integer.MIN_VALUE;
for (int i[] : ar)
res = Math.max(res, max(i));
return res;
}
static int min(int... a)
{
int res = Integer.MAX_VALUE;
for (int i : a)
{
res = Math.min(res, i);
}
return res;
}
static long min(long... a)
{
long res = Long.MAX_VALUE;
for (long i : a)
{
res = Math.min(res, i);
}
return res;
}
static int min(int[][] ar)
{
int res = Integer.MAX_VALUE;
for (int i[] : ar)
res = Math.min(res, min(i));
return res;
}
static int sum(int[] a)
{
int cou = 0;
for (int i : a)
cou += i;
return cou;
}
static int abs(int a)
{
return Math.abs(a);
}
static class FastScanner
{
private BufferedReader reader = null;
private StringTokenizer tokenizer = null;
public FastScanner(InputStream in)
{
reader = new BufferedReader(new InputStreamReader(in));
tokenizer = null;
}
public String next()
{
if (tokenizer == null || !tokenizer.hasMoreTokens())
{
try
{
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e)
{
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
/*public String nextChar(){
return (char)next()[0];
}*/
public String nextLine()
{
if (tokenizer == null || !tokenizer.hasMoreTokens())
{
try
{
return reader.readLine();
} catch (IOException e)
{
throw new RuntimeException(e);
}
}
return tokenizer.nextToken("\n");
}
public long nextLong()
{
return Long.parseLong(next());
}
public int nextInt()
{
return Integer.parseInt(next());
}
public double nextDouble()
{
return Double.parseDouble(next());
}
public int[] nextIntArray(int n)
{
int[] a = new int[n];
for (int i = 0; i < n; i++)
{
a[i] = nextInt();
}
return a;
}
public int[] nextIntArrayDec(int n)
{
int[] a = new int[n];
for (int i = 0; i < n; i++)
{
a[i] = nextInt() - 1;
}
return a;
}
public int[][] nextIntArray2(int h, int w)
{
int[][] a = new int[h][w];
for (int hi = 0; hi < h; hi++)
{
for (int wi = 0; wi < w; wi++)
{
a[hi][wi] = nextInt();
}
}
return a;
}
public int[][] nextIntArray2Dec(int h, int w)
{
int[][] a = new int[h][w];
for (int hi = 0; hi < h; hi++)
{
for (int wi = 0; wi < w; wi++)
{
a[hi][wi] = nextInt() - 1;
}
}
return a;
}
//複数の配列を受け取る
public void nextIntArrays2ar(int[] a, int[] b)
{
for (int i = 0; i < a.length; i++)
{
a[i] = sc.nextInt();
b[i] = sc.nextInt();
}
}
public void nextIntArrays2arDec(int[] a, int[] b)
{
for (int i = 0; i < a.length; i++)
{
a[i] = sc.nextInt() - 1;
b[i] = sc.nextInt() - 1;
}
}
//複数の配列を受け取る
public void nextIntArrays3ar(int[] a, int[] b, int[] c)
{
for (int i = 0; i < a.length; i++)
{
a[i] = sc.nextInt();
b[i] = sc.nextInt();
c[i] = sc.nextInt();
}
}
//複数の配列を受け取る
public void nextIntArrays3arDecLeft2(int[] a, int[] b, int[] c)
{
for (int i = 0; i < a.length; i++)
{
a[i] = sc.nextInt() - 1;
b[i] = sc.nextInt() - 1;
c[i] = sc.nextInt();
}
}
public Integer[] nextIntegerArray(int n)
{
Integer[] a = new Integer[n];
for (int i = 0; i < n; i++)
{
a[i] = nextInt();
}
return a;
}
public char[] nextCharArray(int n)
{
char[] a = next().toCharArray();
return a;
}
public char[][] nextCharArray2(int h, int w)
{
char[][] a = new char[h][w];
for (int i = 0; i < h; i++)
{
a[i] = next().toCharArray();
}
return a;
}
//スペースが入っている場合
public char[][] nextCharArray2s(int h, int w)
{
char[][] a = new char[h][w];
for (int i = 0; i < h; i++)
{
a[i] = nextLine().replace(" ", "").toCharArray();
}
return a;
}
public char[][] nextWrapCharArray2(int h, int w, char c)
{
char[][] a = new char[h + 2][w + 2];
//char c = '*';
int i;
for (i = 0; i < w + 2; i++)
a[0][i] = c;
for (i = 1; i < h + 1; i++)
{
a[i] = (c + next() + c).toCharArray();
}
for (i = 0; i < w + 2; i++)
a[h + 1][i] = c;
return a;
}
//スペースが入ってる時用
public char[][] nextWrapCharArray2s(int h, int w, char c)
{
char[][] a = new char[h + 2][w + 2];
//char c = '*';
int i;
for (i = 0; i < w + 2; i++)
a[0][i] = c;
for (i = 1; i < h + 1; i++)
{
a[i] = (c + nextLine().replace(" ", "") + c).toCharArray();
}
for (i = 0; i < w + 2; i++)
a[h + 1][i] = c;
return a;
}
public long[] nextLongArray(int n)
{
long[] a = new long[n];
for (int i = 0; i < n; i++)
{
a[i] = nextLong();
}
return a;
}
public long[][] nextLongArray2(int h, int w)
{
long[][] a = new long[h][w];
for (int hi = 0; hi < h; hi++)
{
for (int wi = 0; wi < w; wi++)
{
a[hi][wi] = nextLong();
}
}
return a;
}
}
}
| a.cc:1:1: error: 'import' does not name a type
1 | import java.io.*;
| ^~~~~~
a.cc:1:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:2:1: error: 'import' does not name a type
2 | import java.util.*;
| ^~~~~~
a.cc:2:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:8:1: error: expected unqualified-id before 'public'
8 | public class Main
| ^~~~~~
|
s044618123 | p03800 | C++ | import java.io.*;
import java.util.*;
/**
* @author baito
*/
public class Main
{
static StringBuilder sb = new StringBuilder();
static FastScanner sc = new FastScanner(System.in);
static int INF = 12345678;
static long LINF = 123456789123456789L;
static long MINF = -123456789123456789L;
static long MOD = 1000000007;
static int[] y4 = {0, 1, 0, -1};
static int[] x4 = {1, 0, -1, 0};
static int[] y8 = {0, 1, 0, -1, -1, 1, 1, -1};
static int[] x8 = {1, 0, -1, 0, 1, -1, 1, -1};
static long[] F;//factorial
static boolean[] isPrime;
static int[] primes;
static char[][] map;
static int N;
static char[]s;
public static void main(String[] args)
{
N =sc.nextInt();
s = sc.next().toCharArray();
char[] test = new char[N];
//ss
Arrays.fill(test,'.');
test[0] = 's';
test[1] = 's';
if(can(test))pint(test);
//sw
Arrays.fill(test,'.');
test[0] = 's';
test[1] = 'w';
if(can(test))pint(test);
//ws
Arrays.fill(test,'.');
test[0] = 'w';
test[1] = 's';
if(can(test))pint(test);
//ww
Arrays.fill(test,'.');
test[0] = 'w';
test[1] = 'w';
if(can(test))pint(test);
System.out.println("-1");
}
public static boolean can(char[] tes){
for(int i = 2; i < c.length - 1; i++){
}
}
public static long toLong(int[] ar)
{
long res = 0;
for (int i : ar)
{
res *= 10;
res += i;
}
return res;
}
public static int toInt(int[] ar)
{
int res = 0;
for (int i : ar)
{
res *= 10;
res += i;
}
return res;
}
//k個の次の組み合わせをビットで返す 大きさに上限はない 110110 -> 111001
public static int nextCombSizeK(int comb, int k)
{
int x = comb & -comb; //最下位の1
int y = comb + x; //連続した下の1を繰り上がらせる
return ((comb & ~y) / x >> 1) | y;
}
public static int keta(long num)
{
int res = 0;
while (num > 0)
{
num /= 10;
res++;
}
return res;
}
public static long getHashKey(int a, int b)
{
return (long) a << 32 | b;
}
public static boolean isOutofIndex(int x, int y)
{
if (x < 0 || y < 0) return true;
if (map[0].length <= x || map.length <= y) return true;
return false;
}
public static void setPrimes()
{
int n = 100001;
isPrime = new boolean[n];
List<Integer> prs = new ArrayList<>();
Arrays.fill(isPrime, true);
isPrime[0] = isPrime[1] = false;
for (int i = 2; i * i <= n; i++)
{
if (!isPrime[i]) continue;
prs.add(i);
for (int j = i * 2; j < n; j += i)
{
isPrime[j] = false;
}
}
primes = new int[prs.size()];
for (int i = 0; i < prs.size(); i++)
primes[i] = prs.get(i);
}
public static void revSort(int[] a)
{
Arrays.sort(a);
reverse(a);
}
public static void revSort(long[] a)
{
Arrays.sort(a);
reverse(a);
}
public static int[][] copy(int[][] ar)
{
int[][] nr = new int[ar.length][ar[0].length];
for (int i = 0; i < ar.length; i++)
for (int j = 0; j < ar[0].length; j++)
nr[i][j] = ar[i][j];
return nr;
}
/**
* <h1>指定した値以上の先頭のインデクスを返す</h1>
* <p>配列要素が0のときは、0が返る。</p>
*
* @return<b>int</b> : 探索した値以上で、先頭になるインデクス
* 値が無ければ、挿入できる最小のインデックス
*/
public static int lowerBound(final int[] arr, final int value)
{
int low = 0;
int high = arr.length;
int mid;
while (low < high)
{
mid = ((high - low) >>> 1) + low; //(low + high) / 2 (オーバーフロー対策)
if (arr[mid] < value)
{
low = mid + 1;
}
else
{
high = mid;
}
}
return low;
}
/**
* <h1>指定した値より大きい先頭のインデクスを返す</h1>
* <p>配列要素が0のときは、0が返る。</p>
*
* @return<b>int</b> : 探索した値より上で、先頭になるインデクス
* 値が無ければ、挿入できる最小のインデックス
*/
public static int upperBound(final int[] arr, final int value)
{
int low = 0;
int high = arr.length;
int mid;
while (low < high)
{
mid = ((high - low) >>> 1) + low; //(low + high) / 2 (オーバーフロー対策)
if (arr[mid] <= value)
{
low = mid + 1;
}
else
{
high = mid;
}
}
return low;
}
/**
* <h1>指定した値以上の先頭のインデクスを返す</h1>
* <p>配列要素が0のときは、0が返る。</p>
*
* @return<b>int</b> : 探索した値以上で、先頭になるインデクス
* 値がなければ挿入できる最小のインデックス
*/
public static long lowerBound(final long[] arr, final long value)
{
int low = 0;
int high = arr.length;
int mid;
while (low < high)
{
mid = ((high - low) >>> 1) + low; //(low + high) / 2 (オーバーフロー対策)
if (arr[mid] < value)
{
low = mid + 1;
}
else
{
high = mid;
}
}
return low;
}
/**
* <h1>指定した値より大きい先頭のインデクスを返す</h1>
* <p>配列要素が0のときは、0が返る。</p>
*
* @return<b>int</b> : 探索した値より上で、先頭になるインデクス
* 値がなければ挿入できる最小のインデックス
*/
public static long upperBound(final long[] arr, final long value)
{
int low = 0;
int high = arr.length;
int mid;
while (low < high)
{
mid = ((high - low) >>> 1) + low; //(low + high) / 2 (オーバーフロー対策)
if (arr[mid] <= value)
{
low = mid + 1;
}
else
{
high = mid;
}
}
return low;
}
//次の順列に書き換える、最大値ならfalseを返す
public static boolean nextPermutation(int A[])
{
int len = A.length;
int pos = len - 2;
for (; pos >= 0; pos--)
{
if (A[pos] < A[pos + 1]) break;
}
if (pos == -1) return false;
//posより大きい最小の数を二分探索
int ok = pos + 1;
int ng = len;
while (Math.abs(ng - ok) > 1)
{
int mid = (ok + ng) / 2;
if (A[mid] > A[pos]) ok = mid;
else ng = mid;
}
swap(A, pos, ok);
reverse(A, pos + 1, len - 1);
return true;
}
//次の順列に書き換える、最小値ならfalseを返す
public static boolean prevPermutation(int A[])
{
int len = A.length;
int pos = len - 2;
for (; pos >= 0; pos--)
{
if (A[pos] > A[pos + 1]) break;
}
if (pos == -1) return false;
//posより小さい最大の数を二分探索
int ok = pos + 1;
int ng = len;
while (Math.abs(ng - ok) > 1)
{
int mid = (ok + ng) / 2;
if (A[mid] < A[pos]) ok = mid;
else ng = mid;
}
swap(A, pos, ok);
reverse(A, pos + 1, len - 1);
return true;
}
//↓nCrをmod計算するために必要。 ***factorial(N)を呼ぶ必要がある***
static long ncr(int n, int r)
{
if (n < r) return 0;
else if (r == 0) return 1;
factorial(n);
return F[n] / (F[n - r] * F[r]);
}
static long ncr2(int a, int b)
{
if (b == 0) return 1;
else if (a < b) return 0;
long res = 1;
for (int i = 0; i < b; i++)
{
res *= a - i;
res /= i + 1;
}
return res;
}
static long ncrdp(int n, int r)
{
if (n < r) return 0;
long[][] dp = new long[n + 1][r + 1];
for (int ni = 0; ni < n + 1; ni++)
{
dp[ni][0] = dp[ni][ni] = 1;
for (int ri = 1; ri < ni; ri++)
{
dp[ni][ri] = dp[ni - 1][ri - 1] + dp[ni - 1][ri];
}
}
return dp[n][r];
}
static long modNcr(int n, int r)
{
if (n < r) return 0;
long result = F[n];
result = result * modInv(F[n - r]) % MOD;
result = result * modInv(F[r]) % MOD;
return result;
}
public static long modSum(long... lar)
{
long res = 0;
for (long l : lar)
res = (res + l % MOD) % MOD;
return res;
}
public static long modDiff(long a, long b)
{
long res = a - b;
if (res < 0) res += MOD;
res %= MOD;
return res;
}
public static long modMul(long... lar)
{
long res = 1;
for (long l : lar)
res = (res * l) % MOD;
if (res < 0) res += MOD;
res %= MOD;
return res;
}
public static long modDiv(long a, long b)
{
long x = a % MOD;
long y = b % MOD;
long res = (x * modInv(y)) % MOD;
return res;
}
static long modInv(long n)
{
return modPow(n, MOD - 2);
}
static void factorial(int n)
{
F = new long[n + 1];
F[0] = F[1] = 1;
// for (int i = 2; i <= n; i++)
// {
// F[i] = (F[i - 1] * i) % MOD;
// }
//
for (int i = 2; i <= 100000; i++)
{
F[i] = (F[i - 1] * i) % MOD;
}
for (int i = 100001; i <= n; i++)
{
F[i] = (F[i - 1] * i) % MOD;
}
}
static long modPow(long x, long n)
{
long res = 1L;
while (n > 0)
{
if ((n & 1) == 1)
{
res = res * x % MOD;
}
x = x * x % MOD;
n >>= 1;
}
return res;
}
//↑nCrをmod計算するために必要
static int gcd(int n, int r)
{
return r == 0 ? n : gcd(r, n % r);
}
static long gcd(long n, long r)
{
return r == 0 ? n : gcd(r, n % r);
}
static <T> void swap(T[] x, int i, int j)
{
T t = x[i];
x[i] = x[j];
x[j] = t;
}
static void swap(int[] x, int i, int j)
{
int t = x[i];
x[i] = x[j];
x[j] = t;
}
public static void reverse(int[] x)
{
int l = 0;
int r = x.length - 1;
while (l < r)
{
int temp = x[l];
x[l] = x[r];
x[r] = temp;
l++;
r--;
}
}
public static void reverse(long[] x)
{
int l = 0;
int r = x.length - 1;
while (l < r)
{
long temp = x[l];
x[l] = x[r];
x[r] = temp;
l++;
r--;
}
}
public static void reverse(int[] x, int s, int e)
{
int l = s;
int r = e;
while (l < r)
{
int temp = x[l];
x[l] = x[r];
x[r] = temp;
l++;
r--;
}
}
static int length(int a)
{
int cou = 0;
while (a != 0)
{
a /= 10;
cou++;
}
return cou;
}
static int length(long a)
{
int cou = 0;
while (a != 0)
{
a /= 10;
cou++;
}
return cou;
}
static int cou(boolean[] a)
{
int res = 0;
for (boolean b : a)
{
if (b) res++;
}
return res;
}
static int cou(String s, char c)
{
int res = 0;
for (char ci : s.toCharArray())
{
if (ci == c) res++;
}
return res;
}
static int countC2(char[][] a, char c)
{
int co = 0;
for (int i = 0; i < a.length; i++)
for (int j = 0; j < a[0].length; j++)
if (a[i][j] == c) co++;
return co;
}
static int countI(int[] a, int key)
{
int co = 0;
for (int i = 0; i < a.length; i++)
if (a[i] == key) co++;
return co;
}
static int countI(int[][] a, int key)
{
int co = 0;
for (int i = 0; i < a.length; i++)
for (int j = 0; j < a[0].length; j++)
if (a[i][j] == key) co++;
return co;
}
static void fill(int[][] a, int v)
{
for (int i = 0; i < a.length; i++)
for (int j = 0; j < a[0].length; j++)
a[i][j] = v;
}
static void fill(long[][] a, long v)
{
for (int i = 0; i < a.length; i++)
for (int j = 0; j < a[0].length; j++)
a[i][j] = v;
}
static void fill(int[][][] a, int v)
{
for (int i = 0; i < a.length; i++)
for (int j = 0; j < a[0].length; j++)
for (int k = 0; k < a[0][0].length; k++)
a[i][j][k] = v;
}
static int max(int... a)
{
int res = Integer.MIN_VALUE;
for (int i : a)
{
res = Math.max(res, i);
}
return res;
}
static int max(int[][] ar)
{
int res = Integer.MIN_VALUE;
for (int i[] : ar)
res = Math.max(res, max(i));
return res;
}
static int min(int... a)
{
int res = Integer.MAX_VALUE;
for (int i : a)
{
res = Math.min(res, i);
}
return res;
}
static long min(long... a)
{
long res = Long.MAX_VALUE;
for (long i : a)
{
res = Math.min(res, i);
}
return res;
}
static int min(int[][] ar)
{
int res = Integer.MAX_VALUE;
for (int i[] : ar)
res = Math.min(res, min(i));
return res;
}
static int sum(int[] a)
{
int cou = 0;
for (int i : a)
cou += i;
return cou;
}
static int abs(int a)
{
return Math.abs(a);
}
static class FastScanner
{
private BufferedReader reader = null;
private StringTokenizer tokenizer = null;
public FastScanner(InputStream in)
{
reader = new BufferedReader(new InputStreamReader(in));
tokenizer = null;
}
public String next()
{
if (tokenizer == null || !tokenizer.hasMoreTokens())
{
try
{
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e)
{
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
/*public String nextChar(){
return (char)next()[0];
}*/
public String nextLine()
{
if (tokenizer == null || !tokenizer.hasMoreTokens())
{
try
{
return reader.readLine();
} catch (IOException e)
{
throw new RuntimeException(e);
}
}
return tokenizer.nextToken("\n");
}
public long nextLong()
{
return Long.parseLong(next());
}
public int nextInt()
{
return Integer.parseInt(next());
}
public double nextDouble()
{
return Double.parseDouble(next());
}
public int[] nextIntArray(int n)
{
int[] a = new int[n];
for (int i = 0; i < n; i++)
{
a[i] = nextInt();
}
return a;
}
public int[] nextIntArrayDec(int n)
{
int[] a = new int[n];
for (int i = 0; i < n; i++)
{
a[i] = nextInt() - 1;
}
return a;
}
public int[][] nextIntArray2(int h, int w)
{
int[][] a = new int[h][w];
for (int hi = 0; hi < h; hi++)
{
for (int wi = 0; wi < w; wi++)
{
a[hi][wi] = nextInt();
}
}
return a;
}
public int[][] nextIntArray2Dec(int h, int w)
{
int[][] a = new int[h][w];
for (int hi = 0; hi < h; hi++)
{
for (int wi = 0; wi < w; wi++)
{
a[hi][wi] = nextInt() - 1;
}
}
return a;
}
//複数の配列を受け取る
public void nextIntArrays2ar(int[] a, int[] b)
{
for (int i = 0; i < a.length; i++)
{
a[i] = sc.nextInt();
b[i] = sc.nextInt();
}
}
public void nextIntArrays2arDec(int[] a, int[] b)
{
for (int i = 0; i < a.length; i++)
{
a[i] = sc.nextInt() - 1;
b[i] = sc.nextInt() - 1;
}
}
//複数の配列を受け取る
public void nextIntArrays3ar(int[] a, int[] b, int[] c)
{
for (int i = 0; i < a.length; i++)
{
a[i] = sc.nextInt();
b[i] = sc.nextInt();
c[i] = sc.nextInt();
}
}
//複数の配列を受け取る
public void nextIntArrays3arDecLeft2(int[] a, int[] b, int[] c)
{
for (int i = 0; i < a.length; i++)
{
a[i] = sc.nextInt() - 1;
b[i] = sc.nextInt() - 1;
c[i] = sc.nextInt();
}
}
public Integer[] nextIntegerArray(int n)
{
Integer[] a = new Integer[n];
for (int i = 0; i < n; i++)
{
a[i] = nextInt();
}
return a;
}
public char[] nextCharArray(int n)
{
char[] a = next().toCharArray();
return a;
}
public char[][] nextCharArray2(int h, int w)
{
char[][] a = new char[h][w];
for (int i = 0; i < h; i++)
{
a[i] = next().toCharArray();
}
return a;
}
//スペースが入っている場合
public char[][] nextCharArray2s(int h, int w)
{
char[][] a = new char[h][w];
for (int i = 0; i < h; i++)
{
a[i] = nextLine().replace(" ", "").toCharArray();
}
return a;
}
public char[][] nextWrapCharArray2(int h, int w, char c)
{
char[][] a = new char[h + 2][w + 2];
//char c = '*';
int i;
for (i = 0; i < w + 2; i++)
a[0][i] = c;
for (i = 1; i < h + 1; i++)
{
a[i] = (c + next() + c).toCharArray();
}
for (i = 0; i < w + 2; i++)
a[h + 1][i] = c;
return a;
}
//スペースが入ってる時用
public char[][] nextWrapCharArray2s(int h, int w, char c)
{
char[][] a = new char[h + 2][w + 2];
//char c = '*';
int i;
for (i = 0; i < w + 2; i++)
a[0][i] = c;
for (i = 1; i < h + 1; i++)
{
a[i] = (c + nextLine().replace(" ", "") + c).toCharArray();
}
for (i = 0; i < w + 2; i++)
a[h + 1][i] = c;
return a;
}
public long[] nextLongArray(int n)
{
long[] a = new long[n];
for (int i = 0; i < n; i++)
{
a[i] = nextLong();
}
return a;
}
public long[][] nextLongArray2(int h, int w)
{
long[][] a = new long[h][w];
for (int hi = 0; hi < h; hi++)
{
for (int wi = 0; wi < w; wi++)
{
a[hi][wi] = nextLong();
}
}
return a;
}
}
}
| a.cc:1:1: error: 'import' does not name a type
1 | import java.io.*;
| ^~~~~~
a.cc:1:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:2:1: error: 'import' does not name a type
2 | import java.util.*;
| ^~~~~~
a.cc:2:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:8:1: error: expected unqualified-id before 'public'
8 | public class Main
| ^~~~~~
|
s654294789 | p03800 | C++ | #include <iostream>
#include <string>
using namespace std;
int n;
char s[100001] = {}, a[100001] = {}; // a -> animals; s -> answers
string ans;
bool solve(char x, char y){
a[1] = x;
a[2] = y;
bool a, b;
for(int i = 2; i <= n-1; i++)
a[i] == 'S'?
s[i] == 'o' ? a[i+1] = a[i-1] :
a[i-1] == 'S' ? a[i+1] = 'W' : a[i+1] = 'S' :
s[i] == 'x' ? a[i+1] = a[i-1] :
a[i-1] == 'S' ? a[i+1] = 'W' : a[i+1] = 'S';
a = a[n] == 'S' ?
s[n] == 'o' ?
a[n-1] == a[1] ? true : false :
a[n-1] != a[1] ? true : false :
// a[n] == 'W'
s[n] == 'o' ?
a[n-1] == a[1] ? false : true :
a[n-1] != a[1] ? false : true ;
b = a[1] == 'S' ?
s[1] == 'o' ?
a[n] == a[2] ? true : false :
a[n] != a[2] ? true : false :
// a[n] == 'W'
s[1] == 'o' ?
a[n] == a[2] ? false : true :
a[n] != a[2] ? false : true ;
return a && b;
}
int main() {
cin >> n;
for(int h = 1; h <= n; h++) a[h] = '_';
for(int i = 1; i <= n; i++){
cin >> s[i];
}
if(solve('S', 'S')){
for(int k = 1; k <= n; k++) cout << a[k];
cout << endl;
} else if(solve('S', 'W')){
for(int k = 1; k <= n; k++) cout << a[k];
cout << endl;
} else if(solve('W', 'S')){
for(int k = 1; k <= n; k++) cout << a[k];
cout << endl;
} else if(solve('W', 'W')){
for(int k = 1; k <= n; k++) cout << a[k];
cout << endl;
} else cout << "-1" << endl;
return 0;
} | a.cc: In function 'bool solve(char, char)':
a.cc:14:18: error: invalid types 'bool[int]' for array subscript
14 | a[i] == 'S'?
| ^
a.cc:15:40: error: invalid types 'bool[int]' for array subscript
15 | s[i] == 'o' ? a[i+1] = a[i-1] :
| ^
a.cc:15:49: error: invalid types 'bool[int]' for array subscript
15 | s[i] == 'o' ? a[i+1] = a[i-1] :
| ^
a.cc:16:34: error: invalid types 'bool[int]' for array subscript
16 | a[i-1] == 'S' ? a[i+1] = 'W' : a[i+1] = 'S' :
| ^
a.cc:16:50: error: invalid types 'bool[int]' for array subscript
16 | a[i-1] == 'S' ? a[i+1] = 'W' : a[i+1] = 'S' :
| ^
a.cc:16:65: error: invalid types 'bool[int]' for array subscript
16 | a[i-1] == 'S' ? a[i+1] = 'W' : a[i+1] = 'S' :
| ^
a.cc:17:40: error: invalid types 'bool[int]' for array subscript
17 | s[i] == 'x' ? a[i+1] = a[i-1] :
| ^
a.cc:17:49: error: invalid types 'bool[int]' for array subscript
17 | s[i] == 'x' ? a[i+1] = a[i-1] :
| ^
a.cc:18:34: error: invalid types 'bool[int]' for array subscript
18 | a[i-1] == 'S' ? a[i+1] = 'W' : a[i+1] = 'S';
| ^
a.cc:18:50: error: invalid types 'bool[int]' for array subscript
18 | a[i-1] == 'S' ? a[i+1] = 'W' : a[i+1] = 'S';
| ^
a.cc:18:65: error: invalid types 'bool[int]' for array subscript
18 | a[i-1] == 'S' ? a[i+1] = 'W' : a[i+1] = 'S';
| ^
a.cc:19:14: error: invalid types 'bool[int]' for array subscript
19 | a = a[n] == 'S' ?
| ^
a.cc:21:26: error: invalid types 'bool[int]' for array subscript
21 | a[n-1] == a[1] ? true : false :
| ^
a.cc:21:36: error: invalid types 'bool[int]' for array subscript
21 | a[n-1] == a[1] ? true : false :
| ^
a.cc:22:18: error: invalid types 'bool[int]' for array subscript
22 | a[n-1] != a[1] ? true : false :
| ^
a.cc:22:28: error: invalid types 'bool[int]' for array subscript
22 | a[n-1] != a[1] ? true : false :
| ^
a.cc:25:26: error: invalid types 'bool[int]' for array subscript
25 | a[n-1] == a[1] ? false : true :
| ^
a.cc:25:36: error: invalid types 'bool[int]' for array subscript
25 | a[n-1] == a[1] ? false : true :
| ^
a.cc:26:18: error: invalid types 'bool[int]' for array subscript
26 | a[n-1] != a[1] ? false : true ;
| ^
a.cc:26:28: error: invalid types 'bool[int]' for array subscript
26 | a[n-1] != a[1] ? false : true ;
| ^
a.cc:27:14: error: invalid types 'bool[int]' for array subscript
27 | b = a[1] == 'S' ?
| ^
a.cc:29:26: error: invalid types 'bool[int]' for array subscript
29 | a[n] == a[2] ? true : false :
| ^
a.cc:29:34: error: invalid types 'bool[int]' for array subscript
29 | a[n] == a[2] ? true : false :
| ^
a.cc:30:18: error: invalid types 'bool[int]' for array subscript
30 | a[n] != a[2] ? true : false :
| ^
a.cc:30:26: error: invalid types 'bool[int]' for array subscript
30 | a[n] != a[2] ? true : false :
| ^
a.cc:33:26: error: invalid types 'bool[int]' for array subscript
33 | a[n] == a[2] ? false : true :
| ^
a.cc:33:34: error: invalid types 'bool[int]' for array subscript
33 | a[n] == a[2] ? false : true :
| ^
a.cc:34:18: error: invalid types 'bool[int]' for array subscript
34 | a[n] != a[2] ? false : true ;
| ^
a.cc:34:26: error: invalid types 'bool[int]' for array subscript
34 | a[n] != a[2] ? false : true ;
| ^
|
s407969229 | p03800 | C++ | #pragma GCC optimize(2)
#include<bits/stdc++.h>
#include<cstdio>
#define mp make_pair
#define rep(i,n) for(int i=0;i<n;i++)
#define BINF 0x7fffffff
#define INF 0x3f3f3f3f
#define LINF 9223372036854775807
#define END(s) {cout<<s;return 0;}
#define CON(s) {cout<<s;continue;}
#define BRE(s) {cout<<s;break;}
#define pb push_back
#define All(a) a.begin(),a.end() //with A in CAPITAL!!!
#define sz(a) (int)a.size()
#define F first
#define S second
using namespace std;
char buf[100005];
bool istrue[100005];
bool issame[100005];
int n;
bool search(){
for(int i=2;i<n;i++){
if(istrue[i-1]){
if(issame[i-1]){
istrue[i]=istrue[i-2];
} else {
istrue[i]=(!istrue[i-2]);
}
} else {
if(issame[i-1]){
istrue[i]=(!istrue[i-2]);
} else {
istrue[i]=istrue[i-2];
}
}
}
bool ok;
if(istrue[0]){
if(issame[0]){
ok=(istrue[1]==istrue[n-1]);
} else {
ok=(istrue[1]!=istrue[n-1]);
}
} else {
if(issame[0]){
ok=(istrue[1]!=istrue[n-1]);
} else {
ok=(istrue[1]==istrue[n-1]);
}
}
if(istrue[n-1]){
if(issame[n-1]){
ok&=(istrue[n-2]==istrue[0]);
} else {
ok&=(istrue[n-2]!=istrue[0]);
}
} else {
if(issame[n-1]){
ok&=(istrue[n-2]!=istrue[0]);
} else {
ok&=(istrue[n-2]==istrue[0]);
}
}
return ok;
}
int main(){
// ios::sync_with_stdio(false);
cin>>n;
gets(buf); gets(buf);
rep(i,n){
issame[i]=(buf[i]=='o');
}
rep(i,2){
rep(j,2){
istrue[0]=i;
istrue[1]=j;
if(search()){
rep(i,n){
cout<<(istrue[i]?'S':'W');
}
return 0;
}
}
}
cout<<-1;
return 0;
} | a.cc: In function 'int main()':
a.cc:73:9: error: 'gets' was not declared in this scope; did you mean 'getw'?
73 | gets(buf); gets(buf);
| ^~~~
| getw
|
s978154413 | p03800 | C++ | #pragma GCC optimize(2)
#include<bits/stdc++.h>
#define mp make_pair
#define rep(i,n) for(int i=0;i<n;i++)
#define BINF 0x7fffffff
#define INF 0x3f3f3f3f
#define LINF 9223372036854775807
#define END(s) {cout<<s;return 0;}
#define CON(s) {cout<<s;continue;}
#define BRE(s) {cout<<s;break;}
#define pb push_back
#define All(a) a.begin(),a.end() //with A in CAPITAL!!!
#define sz(a) (int)a.size()
#define F first
#define S second
using namespace std;
char buf[100005];
bool istrue[100005];
bool issame[100005];
int n;
bool search(){
for(int i=2;i<n;i++){
if(istrue[i-1]){
if(issame[i-1]){
istrue[i]=istrue[i-2];
} else {
istrue[i]=(!istrue[i-2]);
}
} else {
if(issame[i-1]){
istrue[i]=(!istrue[i-2]);
} else {
istrue[i]=istrue[i-2];
}
}
}
bool ok;
if(istrue[0]){
if(issame[0]){
ok=(istrue[1]==istrue[n-1]);
} else {
ok=(istrue[1]!=istrue[n-1]);
}
} else {
if(issame[0]){
ok=(istrue[1]!=istrue[n-1]);
} else {
ok=(istrue[1]==istrue[n-1]);
}
}
if(istrue[n-1]){
if(issame[n-1]){
ok&=(istrue[n-2]==istrue[0]);
} else {
ok&=(istrue[n-2]!=istrue[0]);
}
} else {
if(issame[n-1]){
ok&=(istrue[n-2]!=istrue[0]);
} else {
ok&=(istrue[n-2]==istrue[0]);
}
}
return ok;
}
int main(){
// ios::sync_with_stdio(false);
cin>>n;
gets(buf); gets(buf);
rep(i,n){
issame[i]=(buf[i]=='o');
}
rep(i,2){
rep(j,2){
istrue[0]=i;
istrue[1]=j;
if(search()){
rep(i,n){
cout<<(istrue[i]?'S':'W');
}
return 0;
}
}
}
cout<<-1;
return 0;
} | a.cc: In function 'int main()':
a.cc:72:9: error: 'gets' was not declared in this scope; did you mean 'getw'?
72 | gets(buf); gets(buf);
| ^~~~
| getw
|
s393663076 | p03800 | C++ | #include<iostream>
#include<Cstdio>
using namespace std;
int num;
string a,ans;
void deal()
{
for(int i=2; i<num; i++)
{
if(ans[i-1]=='S')
{
if(a[i-1]=='o')
ans+=ans[i-2];
else
{
if(ans[i-2]=='S')
ans+='W';
else
ans+='S';
}
}
else
{
if(a[i-1]=='x')
ans+=ans[i-2];
else
{
if(ans[i-2]=='S')
ans+='W';
else
ans+='S';
}
}
}
}
bool check()
{
if(ans[0]=='S')
{
if(a[0]=='o'&&ans[num-1]!=ans[1])
return false;
else if(a[0]=='x'&&ans[num-1]==ans[1])
return false;
}
if(ans[0]=='W')
{
if(a[0]=='x'&&ans[num-1]!=ans[1])
return false;
else if(a[0]=='o'&&ans[num-1]==ans[1])
return false;
}
if(ans[num-1]=='S')
{
if(a[num-1]=='o'&&ans[num-2]!=ans[0])
return false;
else if(a[num-1]=='x'&&ans[num-2]==ans[0])
return false;
}
if(ans[num-1]=='W')
{
// cout<<ans[num-2]<<ans[1]<<endl;
if(a[num-1]=='x'&&ans[num-2]!=ans[0])
return false;
else if(a[num-1]=='o'&&ans[num-2]==ans[0])
return false;
}
return true;
}
int main()
{
cin>>num;
cin>>a;
ans="SS";
deal();
if(check())
cout<<ans<<endl;
else
{
ans="SW";
deal();
if(check())
cout<<ans<<endl;
else
{
ans="WS";
deal();
if(check())
cout<<ans<<endl;
else
{
ans="WW";
deal();
if(check())
cout<<ans<<endl;
else
cout<<"-1"<<endl;
}
}
}
return 0;
}
| a.cc:2:9: fatal error: Cstdio: No such file or directory
2 | #include<Cstdio>
| ^~~~~~~~
compilation terminated.
|
s914944732 | p03800 | C++ | 9:31:51 PM
软1602刘坤 6/2/2018 9:31:51 PM
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <stdio.h>
using namespace std;
const int maxn=1e5+10;
int a[maxn];
char sto[maxn],st[maxn];
int n;
int judge()
{
for (int i=2;i<n-1;i++)
{
if (sto[i]=='w')
{
if (a[i]==1)
sto[i+1]=sto[i-1];
else
{
if (sto[i-1]=='w')
sto[i+1]='l';
else
sto[i+1]='w';
}
}
else if (sto[i]=='l')
{
if (a[i]==1)
{
if (sto[i-1]=='w')
sto[i+1]='l';
else
sto[i+1]='w';
}
else
sto[i+1]=sto[i-1];
}
}
if (sto[n-1]=='w')
{
if (a[n-1]==0)
{
if (sto[n-2]!=sto[0])
return 1;
else
return 0;
}
else
{
if (sto[n-2]==sto[0])
return 1;
else
return 0;
}
}
else if (sto[n-1]=='l')
{
if (a[n-1]==0)
{
if (sto[n-2]==sto[0])
return 1;
else
return 0;
}
else
{
if (sto[n-2]!=sto[0])
return 1;
else
return 0;
}
}
}
void print()
{
for (int i=0;i<n;i++)
{
if (sto[i]=='w')
printf("W");
else
printf("S");
}
printf("\n");
}
int main()
{
scanf("%d",&n);
char ch;
for (int i=0;i<n;i++)
{
cin>>ch;
if (ch=='o')
a[i]=0;
else
a[i]=1;
}
if (a[0]==0)
{
sto[0]='w';sto[1]='l';sto[n-1]='w';
if (judge())
{
print();
return 0;
}
sto[0]='w';sto[1]='w';sto[n-1]='l';
if (judge())
{
print();
return 0;
}
sto[0]='l';sto[1]='w';sto[n-1]='w';
if (judge())
{
print();
return 0;
}
sto[0]='l';sto[1]='l';sto[n-1]='l';
if (judge())
{
print();
return 0;
}
}
else if (a[0]==1)
{
sto[0]='l';sto[1]='l';sto[n-1]='w';
if (judge())
{
print();
return 0;
}
sto[0]='l';sto[1]='w';sto[n-1]='l';
if (judge())
{
print();
return 0;
}
sto[0]='w';sto[1]='w';sto[n-1]='w';
if (judge())
{
print();
return 0;
}
sto[0]='w';sto[1]='l';sto[n-1]='l';
if (judge())
{
print();
return 0;
}
}
printf("-1\n");
return 0;
}
| a.cc:1:1: error: expected unqualified-id before numeric constant
1 | 9:31:51 PM
| ^
In file included from /usr/include/c++/14/iosfwd:42,
from /usr/include/c++/14/ios:40,
from /usr/include/c++/14/ostream:40,
from /usr/include/c++/14/iostream:41,
from a.cc:3:
/usr/include/c++/14/bits/postypes.h:68:11: error: 'ptrdiff_t' does not name a type
68 | typedef ptrdiff_t streamsize; // Signed integral type
| ^~~~~~~~~
/usr/include/c++/14/bits/postypes.h:41:1: note: 'ptrdiff_t' is defined in header '<cstddef>'; this is probably fixable by adding '#include <cstddef>'
40 | #include <cwchar> // For mbstate_t
+++ |+#include <cstddef>
41 |
In file included from /usr/include/c++/14/bits/exception_ptr.h:38,
from /usr/include/c++/14/exception:166,
from /usr/include/c++/14/ios:41:
/usr/include/c++/14/new:131:26: error: declaration of 'operator new' as non-function
131 | _GLIBCXX_NODISCARD void* operator new(std::size_t) _GLIBCXX_THROW (std::bad_alloc)
| ^~~~~~~~
/usr/include/c++/14/new:131:44: error: 'size_t' is not a member of 'std'; did you mean 'size_t'?
131 | _GLIBCXX_NODISCARD void* operator new(std::size_t) _GLIBCXX_THROW (std::bad_alloc)
| ^~~~~~
In file included from /usr/include/wchar.h:35,
from /usr/include/c++/14/cwchar:44,
from /usr/include/c++/14/bits/postypes.h:40:
/usr/lib/gcc/x86_64-linux-gnu/14/include/stddef.h:214:23: note: 'size_t' declared here
214 | typedef __SIZE_TYPE__ size_t;
| ^~~~~~
/usr/include/c++/14/new:132:41: error: attributes after parenthesized initializer ignored [-fpermissive]
132 | __attribute__((__externally_visible__));
| ^
/usr/include/c++/14/new:133:26: error: declaration of 'operator new []' as non-function
133 | _GLIBCXX_NODISCARD void* operator new[](std::size_t) _GLIBCXX_THROW (std::bad_alloc)
| ^~~~~~~~
/usr/include/c++/14/new:133:46: error: 'size_t' is not a member of 'std'; did you mean 'size_t'?
133 | _GLIBCXX_NODISCARD void* operator new[](std::size_t) _GLIBCXX_THROW (std::bad_alloc)
| ^~~~~~
/usr/lib/gcc/x86_64-linux-gnu/14/include/stddef.h:214:23: note: 'size_t' declared here
214 | typedef __SIZE_TYPE__ size_t;
| ^~~~~~
/usr/include/c++/14/new:134:41: error: attributes after parenthesized initializer ignored [-fpermissive]
134 | __attribute__((__externally_visible__));
| ^
/usr/include/c++/14/new:140:29: error: 'std::size_t' has not been declared
140 | void operator delete(void*, std::size_t) _GLIBCXX_USE_NOEXCEPT
| ^~~
/usr/include/c++/14/new:142:31: error: 'std::size_t' has not been declared
142 | void operator delete[](void*, std::size_t) _GLIBCXX_USE_NOEXCEPT
| ^~~
/usr/include/c++/14/new:145:26: error: declaration of 'operator new' as non-function
145 | _GLIBCXX_NODISCARD void* operator new(std::size_t, const std::nothrow_t&) _GLIBCXX_USE_NOEXCEPT
| ^~~~~~~~
/usr/include/c++/14/new:145:44: error: 'size_t' is not a member of 'std'; did you mean 'size_t'?
145 | _GLIBCXX_NODISCARD void* operator new(std::size_t, const std::nothrow_t&) _GLIBCXX_USE_NOEXCEPT
| ^~~~~~
/usr/lib/gcc/x86_64-linux-gnu/14/include/stddef.h:214:23: note: 'size_t' declared here
214 | typedef __SIZE_TYPE__ size_t;
| ^~~~~~
/usr/include/c++/14/new:145:52: error: expected primary-expression before 'const'
145 | _GLIBCXX_NODISCARD void* operator new(std::size_t, const std::nothrow_t&) _GLIBCXX_USE_NOEXCEPT
| ^~~~~
/usr/include/c++/14/new:147:26: error: declaration of 'operator new []' as non-function
147 | _GLIBCXX_NODISCARD void* operator new[](std::size_t, const std::nothrow_t&) _GLIBCXX_USE_NOEXCEPT
| ^~~~~~~~
/usr/include/c++/14/new:147:46: error: 'size_t' is not a member of 'std'; did you mean 'size_t'?
147 | _GLIBCXX_NODISCARD void* operator new[](std::size_t, const std::nothrow_t&) _GLIBCXX_USE_NOEXCEPT
| ^~~~~~
/usr/lib/gcc/x86_64-linux-gnu/14/include/stddef.h:214:23: note: 'size_t' declared here
214 | typedef __SIZE_TYPE__ size_t;
| ^~~~~~
/usr/include/c++/14/new:147:54: error: expected primary-expression before 'const'
147 | _GLIBCXX_NODISCARD void* operator new[](std::size_t, const std::nothrow_t&) _GLIBCXX_USE_NOEXCEPT
| ^~~~~
/usr/include/c++/14/new:154:26: error: declaration of 'operator new' as non-function
154 | _GLIBCXX_NODISCARD void* operator new(std::size_t, std::align_val_t)
| ^~~~~~~~
/usr/include/c++/14/new:154:44: error: 'size_t' is not a member of 'std'; did you mean 'size_t'?
154 | _GLIBCXX_NODISCARD void* operator new(std::size_t, std::align_val_t)
| ^~~~~~
/usr/lib/gcc/x86_64-linux-gnu/14/include/stddef.h:214:23: note: 'size_t' declared here
214 | typedef __SIZE_TYPE__ size_t;
| ^~~~~~
/usr/include/c++/14/new:154:68: error: expected primary-expression before ')' token
154 | _GLIBCXX_NODISCARD void* operator new(std::size_t, std::align_val_t)
| ^
/usr/include/c++/14/new:155:73: error: attributes after parenthesized initializer ignored [-fpermissive]
155 | __attribute__((__externally_visible__, __alloc_size__ (1), __malloc__));
| ^
/usr/include/c++/14/new:156:26: error: declaration of 'operator new' as non-function
156 | _GLIBCXX_NODISCARD void* operator new(std::size_t, std::align_val_t, const std::nothrow_t&)
| ^~~~~~~~
/usr/include/c++/14/new:156:44: error: 'size_t' is not a member of 'std'; did you mean 'size_t'?
156 | _GLIBCXX_NODISCARD void* operator new(std::size_t, std::align_val_t, const std::nothrow_t&)
| ^~~~~~
/usr/lib/gcc/x86_64-linux-gnu/14/include/stddef.h:214:23: note: 'size_t' declared here
214 | typedef __SIZE_TYPE__ size_t;
| ^~~~~~
/usr/include/c++/14/new:156:68: error: expected primary-expression before ',' token
156 | _GLIBCXX_NODISCARD void* operator new(std::size_t, std::align_val_t, const std::nothrow_t&)
| ^
/usr/include/c++/14/new:156:70: error: expected primary-expression before 'const'
156 | _GLIBCXX_NODISCARD void* operator new(std::size_t, std::align_val_t, const std::nothrow_t&)
| ^~~~~
/usr/include/c++/14/new:162:26: error: declaration of 'operator new []' as non-function
162 | _GLIBCXX_NODISCARD void* operator new[](std::size_t, std::align_val_t)
| ^~~~~~~~
/usr/include/c++/14/new:162:46: error: 'size_t' is not a member of 'std'; did you mean 'size_t'?
162 | _GLIBCXX_NODISCARD void* operator new[](std::size_t, std::align_val_t)
| ^~~~~~
/usr/lib/gcc/x86_64-linux-gnu/14/include/stddef.h:214:23: note: 'size_t' declared here
214 | typedef __SIZE_TYPE__ size_t;
| ^~~~~~
/usr/include/c++/14/new:162:70: error: expected primary-expression before ')' token
162 | _GLIBCXX_NODISCARD void* operator new[](std::size_t, std::align_val_t)
| ^
/usr/include/c++/14/new:163:73: error: attributes after parenthesized initializer ignored [-fpermissive]
163 | __attribute__((__externally_visible__, __alloc_size__ (1), __malloc__));
| ^
/usr/include/c++/14/new:164:26: error: declaration of 'operator new []' as non-function
164 | _GLIBCXX_NODISCARD void* operator new[](std::size_t, std::align_val_t, const std::nothrow_t&)
| ^~~~~~~~
/usr/include/c++/14/new:164:46: error: 'size_t' is not a member of 'std'; did you mean 'size_t'?
164 | _GLIBCXX_NODISCARD void* operator new[](std::size_t, std::align_val_t, const std::nothrow_t&)
| ^~~~~~
/usr/lib/gcc/x86_64-linux-gnu/14/include/stddef.h:214:23: note: 'size_t' declared here
214 | typedef __SIZE_TYPE__ size_t;
| ^~~~~~
/usr/include/c++/14/new:164:70: error: expected primary-expression before ',' token
164 | _GLIBCXX_NODISCARD void* operator new[](std::size_t, std::align_val_t, const std::nothrow_t&)
| ^
/usr/include/c++/14/new:164:72: error: expected primary-expression before 'const'
164 | _GLIBCXX_NODISCARD void* operator new[](std::size_t, std::align_val_t, const std::nothrow_t&)
| ^~~~~
/usr/include/c++/14/new:171:29: error: 'std::size_t' has not been declared
171 | void operator delete(void*, std::size_t, std::align_val_t)
| ^~~
/usr/include/c++/14/new:173:31: error: 'std::size_t' has not been declared
173 | void operator delete[](void*, std::size_t, std::align_val_t)
| ^~~
/usr/include/c++/14/new:179:33: error: declaration of 'operator new' as non-function
179 | _GLIBCXX_NODISCARD inline void* operator new(std::size_t, void* __p) _GLIBCXX_USE_NOEXCEPT
| ^~~~~~~~
/usr/include/c++/14/new:179:51: error: 'size_t' is not a member of 'std'; did you mean 'size_t'?
179 | _GLIB |
s621572632 | p03800 | C++ | #include<stdio.h>
#include<iostream>
#include<string>
using namespace std;
string lie;
int zhong[1000005];
bool zhao(int a){
for(int i=2;i<a;i++){
if(lie[i-1]=='o'){
if(zhong[i-1]==0)zhong[i]=zhong[i-2];
else zhong[i]=(zhong[i-2]+1)%2;
}
else{
if(zhong[i-1]==1)zhong[i]=zhong[i-2];
else zhong[i]=(zhong[i-2]+1)%2;
}
}
int s,s2;
if(lie[a-1]=='o'){
if(zhong[a-1]==0)s=zhong[a-2];
else s=(zhong[a-2]+1)%2;
}
else{
if(zhong[a-1]==1)s=zhong[a-2];
else s=(zhong[a-2]+1)%2;
}
if(lie[1]=='o'){
if(zhong[1]==0)s1=zhong[2];
else s1=(zhong[2]+1)%2;
}
else{
if(zhong[1]==1)s1=zhong[2];
else s1=(zhong[2]+1)%2;
}
if(s==zhong[0]&&s1==zhong[a-1]){
for(int i=0;i<a;i++){
if(zhong[i]==0)printf("S");
else printf("W");
}puts("");return 1;
}
else return 0;
}
int main(){
int n;
cin>>n>>lie;
zhong[0]=0;zhong[1]=0;
if(zhao(n)==1)return 0;
zhong[0]=1;zhong[1]=0;
if(zhao(n)==1)return 0;
zhong[0]=0;zhong[1]=1;
if(zhao(n)==1)return 0;
zhong[0]=1;zhong[1]=1;
if(zhao(n)==1)return 0;
printf("-1\n");return 0;
}
| a.cc: In function 'bool zhao(int)':
a.cc:28:24: error: 's1' was not declared in this scope; did you mean 's2'?
28 | if(zhong[1]==0)s1=zhong[2];
| ^~
| s2
a.cc:29:14: error: 's1' was not declared in this scope; did you mean 's2'?
29 | else s1=(zhong[2]+1)%2;
| ^~
| s2
a.cc:32:24: error: 's1' was not declared in this scope; did you mean 's2'?
32 | if(zhong[1]==1)s1=zhong[2];
| ^~
| s2
a.cc:33:14: error: 's1' was not declared in this scope; did you mean 's2'?
33 | else s1=(zhong[2]+1)%2;
| ^~
| s2
a.cc:35:21: error: 's1' was not declared in this scope; did you mean 's2'?
35 | if(s==zhong[0]&&s1==zhong[a-1]){
| ^~
| s2
a.cc:42:1: warning: control reaches end of non-void function [-Wreturn-type]
42 | }
| ^
|
s293891452 | p03800 | C++ | #include <iostream>
#include <queue>
#include <map>
#include <list>
#include <vector>
#include <string>
#include <stack>
#include <limits>
#include <climits>
#include <cassert>
#include <fstream>
#include <cstring>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <cstdio>
#include <ciso646>
#include <set>
#include <array>
#include <unordered_map>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define inf 0x3f3f3f3f
#define PB push_back
#define MP make_pair
#define ALL(a) (a).begin(),(a).end()
#define SET(a,c) memset(a,c,sizeof a)
#define CLR(a) memset(a,0,sizeof a)
#define VS vector<string>
#define VI vector<ll>
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define MIN(a,b) (a>b?b:a)
#define MAX(a,b) (a>b?a:b)
#define pi 2*acos(0.0)
#define INFILE() freopen("in0.txt","r",stdin)
#define OUTFILE()freopen("out0.txt","w",stdout)
#define ll long long
#define ull unsigned long long
#define pii pair<ll,ll>
#define pcc pair<char,char>
#define pic pair<ll,char>
#define pci pair<char,ll>
#define eps 1e-14
#define FST first
#define SEC second
#define SETUP cin.tie(0), ios::sync_with_stdio(false), cout << setprecision(15)
namespace {
struct input_returnner {
ll N; input_returnner(ll N_ = 0) :N(N_) {}
template<typename T> operator vector<T>() const { vector<T> res(N); for (auto &a : res) cin >> a; return std::move(res); }
template<typename T> operator T() const { T res; cin >> res; return res; }
template<typename T> T operator - (T right) { return T(input_returnner()) - right; }
template<typename T> T operator + (T right) { return T(input_returnner()) + right; }
template<typename T> T operator * (T right) { return T(input_returnner()) * right; }
template<typename T> T operator / (T right) { return T(input_returnner()) / right; }
template<typename T> T operator << (T right) { return T(input_returnner()) << right; }
template<typename T> T operator >> (T right) { return T(input_returnner()) >> right; }
};
template<typename T> input_returnner in() { return in<T>(); }
input_returnner in() { return input_returnner(); }
input_returnner in(ll N) { return std::move(input_returnner(N)); }
}
ll MOD = 1e9 + 7;
void solve();
signed main() {
SETUP;
solve();
#ifdef _DEBUG
system("pause");
#endif
return 0;
}
#define int ll
bool IsSheep(bool tar, bool opp) {
return not (tar ^ opp);
}
bool f(vector<bool>& isS, const vector<bool>& field) {
FOR(i, 1, isS.size()-1) {
isS[i + 1] = ((field[i] ^ isS[i]) ^ isS[i - 1]);
}
REP(i, isS.size()){
if (isS[(i + 1) % isS.size()] != ((field[i] ^ isS[i]) ^ isS[(i - 1 + isS.size()) % isS.size()])) return false;
}
return true;
}
void solve() {
int N; cin >> N;
string s; cin >> s;
vector<bool> isS(N);
vector<bool> field(N);
REP(i, N) {
field[i] = (s[i] == 'o');
}
for (int i = 0; i < 4; ++i) {
bitset<2> b(i);
isS[0] = b[0];
isS[1] = b[1];
if (f(isS, field)) {
for (auto &a : isS) {
cout << (a ? 'S' : 'W');
}
cout << endl;
return;
}
}
cout << -1 << endl;
}
| a.cc: In function 'void solve()':
a.cc:115:40: error: cannot bind non-const lvalue reference of type 'std::_Bit_reference&' to an rvalue of type 'std::_Bit_iterator::reference'
115 | for (auto &a : isS) {
| ^~~
|
s787904584 | p03800 | C++ | #include <bits/stdc++.h>
#include <sys/time.h>
using namespace std;
#define rep(i,n) for(long long i = 0; i < (long long)(n); i++)
#define repi(i,a,b) for(long long i = (long long)(a); i < (long long)(b); i++)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define mt make_tuple
#define mp make_pair
template<class T1, class T2> bool chmin(T1 &a, T2 b) { return b < a && (a = b, true); }
template<class T1, class T2> bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
using ll = long long; using vll = vector<ll>; using vvll = vector<vll>; using P = pair<ll, ll>;
using ld = long double; using vld = vector<ld>;
using vi = vector<int>; using vvi = vector<vi>; vll conv(vi& v) { vll r(v.size()); rep(i, v.size()) r[i] = v[i]; return r; }
inline void input(int &v){ v=0;char c=0;int p=1; while(c<'0' || c>'9'){if(c=='-')p=-1;c=getchar();} while(c>='0' && c<='9'){v=(v<<3)+(v<<1)+c-'0';c=getchar();} v*=p; } // これを使うならば、tieとかを消して!!
template <typename T, typename U> ostream &operator<<(ostream &o, const pair<T, U> &v) { o << "(" << v.first << ", " << v.second << ")"; return o; }
template<size_t...> struct seq{}; template<size_t N, size_t... Is> struct gen_seq : gen_seq<N-1, N-1, Is...>{}; template<size_t... Is> struct gen_seq<0, Is...> : seq<Is...>{};
template<class Ch, class Tr, class Tuple, size_t... Is>
void print_tuple(basic_ostream<Ch,Tr>& os, Tuple const& t, seq<Is...>){ using s = int[]; (void)s{0, (void(os << (Is == 0? "" : ", ") << get<Is>(t)), 0)...}; }
template<class Ch, class Tr, class... Args>
auto operator<<(basic_ostream<Ch, Tr>& os, tuple<Args...> const& t) -> basic_ostream<Ch, Tr>& { os << "("; print_tuple(os, t, gen_seq<sizeof...(Args)>()); return os << ")"; }
ostream &operator<<(ostream &o, const vvll &v) { rep(i, v.size()) { rep(j, v[i].size()) o << v[i][j] << " "; o << endl; } return o; }
template <typename T> ostream &operator<<(ostream &o, const vector<T> &v) { o << '['; rep(i, v.size()) o << v[i] << (i != v.size()-1 ? ", " : ""); o << "]"; return o; }
template <typename T> ostream &operator<<(ostream &o, const deque<T> &v) { o << '['; rep(i, v.size()) o << v[i] << (i != v.size()-1 ? ", " : ""); o << "]"; return o; }
template <typename T> ostream &operator<<(ostream &o, const set<T> &m) { o << '['; for (auto it = m.begin(); it != m.end(); it++) o << *it << (next(it) != m.end() ? ", " : ""); o << "]"; return o; }
template <typename T> ostream &operator<<(ostream &o, const unordered_set<T> &m) { o << '['; for (auto it = m.begin(); it != m.end(); it++) o << *it << (next(it) != m.end() ? ", " : ""); o << "]"; return o; }
template <typename T, typename U> ostream &operator<<(ostream &o, const map<T, U> &m) { o << '['; for (auto it = m.begin(); it != m.end(); it++) o << *it << (next(it) != m.end() ? ", " : ""); o << "]"; return o; }
template <typename T, typename U, typename V> ostream &operator<<(ostream &o, const unordered_map<T, U, V> &m) { o << '['; for (auto it = m.begin(); it != m.end(); it++) o << *it; o << "]"; return o; }
vector<int> range(const int x, const int y) { vector<int> v(y - x + 1); iota(v.begin(), v.end(), x); return v; }
template <typename T> istream& operator>>(istream& i, vector<T>& o) { rep(j, o.size()) i >> o[j]; return i;}
template <typename T, typename S, typename U> ostream &operator<<(ostream &o, const priority_queue<T, S, U> &v) { auto tmp = v; while (tmp.size()) { auto x = tmp.top(); tmp.pop(); o << x << " ";} return o; }
template <typename T> ostream &operator<<(ostream &o, const queue<T> &v) { auto tmp = v; while (tmp.size()) { auto x = tmp.front(); tmp.pop(); o << x << " ";} return o; }
template <typename T> ostream &operator<<(ostream &o, const stack<T> &v) { auto tmp = v; while (tmp.size()) { auto x = tmp.top(); tmp.pop(); o << x << " ";} return o; }
template <typename T> unordered_map<T, ll> counter(vector<T> vec){unordered_map<T, ll> ret; for (auto&& x : vec) ret[x]++; return ret;};
string substr(string s, P x) {return s.substr(x.fi, x.se - x.fi); }
void vizGraph(vvll& g, int mode = 0, string filename = "out.png") { ofstream ofs("./out.dot"); ofs << "digraph graph_name {" << endl; set<P> memo; rep(i, g.size()) rep(j, g[i].size()) { if (mode && (memo.count(P(i, g[i][j])) || memo.count(P(g[i][j], i)))) continue; memo.insert(P(i, g[i][j])); ofs << " " << i << " -> " << g[i][j] << (mode ? " [arrowhead = none]" : "")<< endl; } ofs << "}" << endl; ofs.close(); system(((string)"dot -T png out.dot >" + filename).c_str()); }
size_t random_seed; namespace std { using argument_type = P; template<> struct hash<argument_type> { size_t operator()(argument_type const& x) const { size_t seed = random_seed; seed ^= hash<ll>{}(x.fi); seed ^= (hash<ll>{}(x.se) << 1); return seed; } }; }; // hash for various class
struct timeval start; double sec() { struct timeval tv; gettimeofday(&tv, NULL); return (tv.tv_sec - start.tv_sec) + (tv.tv_usec - start.tv_usec) * 1e-6; }
struct init_{init_(){ ios::sync_with_stdio(false); cin.tie(0); gettimeofday(&start, NULL); struct timeval myTime; struct tm *time_st; gettimeofday(&myTime, NULL); time_st = localtime(&myTime.tv_sec); srand(myTime.tv_usec); random_seed = RAND_MAX / 2 + rand() / 2; }} init__;
#define ldout fixed << setprecision(40)
#define EPS (double)1e-14
#define INF (ll)1e18
#define mo (ll)(1e9+7)
int main(void) {
ll n;cin>>n;
string s;cin>>s;
rep(mask,4) {
vector<bool> x(3*n);
x[0] = mask & 1;
x[1] = mask & 2;
repi(i, 2, 3*n) {
x[i] = x[i-1] ^ x[i-2] ^ (s[(i-1)%n] == 'x');
}
// cout << x << endl;
ll faf = 1;
rep(i, n) {
if (x[i] != x[i+n]) {
faf = 0;
break;
}
}
if (faf) {
rep(i, n) {
cout << (x[i] ? 'W' : 'S');
}
cout << endl;
return 0
}
}
cout << -1<<endl;
return 0;
}
| a.cc: In function 'int main()':
a.cc:74:21: error: expected ';' before '}' token
74 | return 0
| ^
| ;
75 | }
| ~
|
s387202002 | p03800 | C | #include <cstdio>
int n;
char s[100001],r[100001];
bool c(char a,char b)
{
r[0]=a;
r[1]=b;
for (int i=2; i<n; ++i)
r[i]=r[i-1]=='S'?s[i-1]=='o'?r[i-2]:r[i-2]=='S'?'W':'S':s[i-1]=='x'?r[i-2]:r[i-2]=='S'?'W':'S';
return !(r[n-1]=='S'&&((s[n-1]=='o'&&r[n-2]!=r[0])||(s[n-1]=='x'&&r[n-2]==r[0])))&&
!(r[0]=='S'&&((s[0]=='o'&&r[1]!=r[n-1])||(s[0]=='x'&&r[1]==r[n-1])))&&
!(r[n-1]=='W'&&((s[n-1]=='x'&&r[n-2]!=r[0])||(s[n-1]=='o'&&r[n-2]==r[0])))&&
!(r[0]=='W'&&((s[0]=='x'&&r[1]!=r[n-1])||(s[0]=='o'&&r[1]==r[n-1])));
}
int main()
{
scanf("%d%s",&n,s);
puts(c('S','W')||c('W','S')||c('W','W')||c('S','S')?r:"-1");
return 0;
} | main.c:1:10: fatal error: cstdio: No such file or directory
1 | #include <cstdio>
| ^~~~~~~~
compilation terminated.
|
s616174108 | p03800 | C++ | #include<string>
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<map>
using namespace std;
typedef long long int llint;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
const int mod=1000000007;
const llint big=1e18+10;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-9;
template <class T,class U>void mineq(T& a,U b){if(a>b){a=b;}}
template <class T,class U>void maxeq(T& a,U b){if(a<b){a=b;}}
int gcd(int a,int b){if(a%b==0){return b;}else return gcd(b,a%b);}//a>b
class in_t{public:
int a;in_t(){cin>>a;}
operator int() {return a;}
};
class lin_t{public:
llint a;lin_t(){cin>>a;}
operator llint() {return a;}
};
class ld_t{public:
long double a;ld_t(){cin>>a;}
operator long double() {return a;}
};
int main(void){
in_t n;
string str;cin>>str;
//o->SSS,WSW
string ans;
ans.res(n+2);
for(int ba=0;ba<4;ba++){
if(ba==0){ans[0]='S',ans[1]='S';}
if(ba==1){ans[0]='S',ans[1]='W';}
if(ba==2){ans[0]='W',ans[1]='S';}
if(ba==3){ans[0]='W',ans[1]='W';}
for(i=1;i<=n;i++){
int bi=0;
if(ans[i-1]=='W'){bi++;}
if(ans[i]=='W'){bi++;}
if(str[i-1]=='x'){bi++;}
if(bi%2==0){ans[i+1]='S';}
else{ans[i+1]='W';}
}
if(!(ans[0]==ans[n]&&ans[1]==ans[n+1])){continue;}
ans.pob();ans.pob();
cout<<ans<<endl;return 0;
}
cout<<"-1"<<endl;
return 0;
}
| a.cc: In function 'int main()':
a.cc:59:21: error: 'i' was not declared in this scope
59 | for(i=1;i<=n;i++){
| ^
|
s271627151 | p03800 | C++ | #include<string>
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<map>
using namespace std;
typedef long long int llint;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
const int mod=1000000007;
const llint big=1e18+10;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-9;
template <class T,class U>void mineq(T& a,U b){if(a>b){a=b;}}
template <class T,class U>void maxeq(T& a,U b){if(a<b){a=b;}}
int gcd(int a,int b){if(a%b==0){return b;}else return gcd(b,a%b);}//a>b
class in_t{public:
int a;in_t(){cin>>a;}
operator int() {return a;}
};
class lin_t{public:
llint a;lin_t(){cin>>a;}
operator llint() {return a;}
};
class ld_t{public:
long double a;ld_t(){cin>>a;}
operator long double() {return a;}
};
int main(void){
in_t n;
string str;cin>>str;
//o->SSS,WSW
string ans(n+2);
for(int ba=0;ba<4;ba++){
if(ba==0){ans[0]='S',ans[1]='S';}
if(ba==1){ans[0]='S',ans[1]='W';}
if(ba==2){ans[0]='W',ans[1]='S';}
if(ba==3){ans[0]='W',ans[1]='W';}
for(i=1;i<=n;i++){
int bi=0;
if(ans[i-1]=='W'){bi++;}
if(ans[i]=='W'){bi++;}
if(str[i-1]=='x'){bi++;}
if(bi%2==0){ans[i+1]='S';}
else{ans[i+1]='W';}
}
if(!(ans[0]==ans[n]&&ans[1]==ans[n+1])){continue;}
ans.pob();ans.pob();
cout<<ans<<endl;return 0;
}
cout<<"-1"<<endl;
return 0;
} | a.cc: In function 'int main()':
a.cc:52:23: error: no matching function for call to 'std::__cxx11::basic_string<char>::basic_string(int)'
52 | string ans(n+2);
| ^
In file included from /usr/include/c++/14/string:54,
from a.cc:1:
/usr/include/c++/14/bits/basic_string.h:800:9: note: candidate: 'template<class _Tp, class> std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string(const _Tp&, const _Alloc&) [with <template-parameter-2-2> = _Tp; _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]'
800 | basic_string(const _Tp& __t, const _Alloc& __a = _Alloc())
| ^~~~~~~~~~~~
/usr/include/c++/14/bits/basic_string.h:800:9: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/14/bits/char_traits.h:50,
from /usr/include/c++/14/string:42:
/usr/include/c++/14/type_traits: In substitution of 'template<bool _Cond, class _Tp> using std::enable_if_t = typename std::enable_if::type [with bool _Cond = false; _Tp = void]':
/usr/include/c++/14/bits/basic_string.h:149:8: required by substitution of 'template<class _CharT, class _Traits, class _Alloc> template<class _Tp, class _Res> using std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::_If_sv = std::enable_if_t<((bool)std::__and_<std::is_convertible<const _Tp&, std::basic_string_view<_CharT, _Traits> >, std::__not_<std::is_convertible<const _Tp*, const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>*> >, std::__not_<std::is_convertible<const _Tp&, const _CharT*> > >::value), _Res> [with _Tp = int; _Res = void; _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]'
149 | using _If_sv = enable_if_t<
| ^~~~~~
/usr/include/c++/14/bits/basic_string.h:797:30: required from here
797 | template<typename _Tp, typename = _If_sv<_Tp, void>>
| ^~~~~~~~
/usr/include/c++/14/type_traits:2711:11: error: no type named 'type' in 'struct std::enable_if<false, void>'
2711 | using enable_if_t = typename enable_if<_Cond, _Tp>::type;
| ^~~~~~~~~~~
/usr/include/c++/14/bits/basic_string.h:788:9: note: candidate: 'template<class _Tp, class> std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string(const _Tp&, size_type, size_type, const _Alloc&) [with <template-parameter-2-2> = _Tp; _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]'
788 | basic_string(const _Tp& __t, size_type __pos, size_type __n,
| ^~~~~~~~~~~~
/usr/include/c++/14/bits/basic_string.h:788:9: note: candidate expects 3 arguments, 1 provided
/usr/include/c++/14/bits/basic_string.h:765:9: note: candidate: 'template<class _InputIterator, class> std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string(_InputIterator, _InputIterator, const _Alloc&) [with <template-parameter-2-2> = _InputIterator; _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]'
765 | basic_string(_InputIterator __beg, _InputIterator __end,
| ^~~~~~~~~~~~
/usr/include/c++/14/bits/basic_string.h:765:9: note: candidate expects 2 arguments, 1 provided
/usr/include/c++/14/bits/basic_string.h:669:7: note: candidate: 'template<class> std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string(size_type, _CharT, const _Alloc&) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]'
669 | basic_string(size_type __n, _CharT __c, const _Alloc& __a = _Alloc())
| ^~~~~~~~~~~~
/usr/include/c++/14/bits/basic_string.h:669:7: note: candidate expects 2 arguments, 1 provided
/usr/include/c++/14/bits/basic_string.h:646:7: note: candidate: 'template<class> std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string(const _CharT*, const _Alloc&) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]'
646 | basic_string(const _CharT* __s, const _Alloc& __a = _Alloc())
| ^~~~~~~~~~~~
/usr/include/c++/14/bits/basic_string.h:646:7: note: template argument deduction/substitution failed:
a.cc:52:21: note: cannot convert '(n.in_t::operator int() + 2)' (type 'int') to type 'const char*'
52 | string ans(n+2);
| ~^~
/usr/include/c++/14/bits/basic_string.h:721:7: note: candidate: 'std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string(std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&&, const _Alloc&) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]'
721 | basic_string(basic_string&& __str, const _Alloc& __a)
| ^~~~~~~~~~~~
/usr/include/c++/14/bits/basic_string.h:721:7: note: candidate expects 2 arguments, 1 provided
/usr/include/c++/14/bits/basic_string.h:716:7: note: candidate: 'std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string(const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&, const _Alloc&) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]'
716 | basic_string(const basic_string& __str, const _Alloc& __a)
| ^~~~~~~~~~~~
/usr/include/c++/14/bits/basic_string.h:716:7: note: candidate expects 2 arguments, 1 provided
/usr/include/c++/14/bits/basic_string.h:711:7: note: candidate: 'std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string(std::initializer_list<_Tp>, const _Alloc&) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]'
711 | basic_string(initializer_list<_CharT> __l, const _Alloc& __a = _Alloc())
| ^~~~~~~~~~~~
/usr/include/c++/14/bits/basic_string.h:711:45: note: no known conversion for argument 1 from 'int' to 'std::initializer_list<char>'
711 | basic_string(initializer_list<_CharT> __l, const _Alloc& __a = _Alloc())
| ~~~~~~~~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/basic_string.h:682:7: note: candidate: 'std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string(std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&&) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]'
682 | basic_string(basic_string&& __str) noexcept
| ^~~~~~~~~~~~
/usr/include/c++/14/bits/basic_string.h:682:35: note: no known conversion for argument 1 from 'int' to 'std::__cxx11::basic_string<char>&&'
682 | basic_string(basic_string&& __str) noexcept
| ~~~~~~~~~~~~~~~^~~~~
/usr/include/c++/14/bits/basic_string.h:624:7: note: candidate: 'std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string(const _CharT*, size_type, const _Alloc&) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>; size_type = long unsigned int]'
624 | basic_string(const _CharT* __s, size_type __n,
| ^~~~~~~~~~~~
/usr/include/c++/14/bits/basic_string.h:624:7: note: candidate expects 3 arguments, 1 provided
/usr/include/c++/14/bits/basic_string.h:604:7: note: candidate: 'std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string(const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&, size_type, size_type, const _Alloc&) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>; size_type = long unsigned int]'
604 | basic_string(const basic_string& __str, size_type __pos,
| ^~~~~~~~~~~~
/usr/include/c++/14/bits/basic_string.h:604:7: note: candidate expects 4 arguments, 1 provided
/usr/include/c++/14/bits/basic_string.h:586:7: note: candidate: 'std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string(const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&, size_type, size_type) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>; size_type = long unsigned int]'
586 | basic_string(const basic_string& __str, size_type __pos,
| ^~~~~~~~~~~~
/usr/include/c++/14/bits/basic_string.h:586:7: note: candidate expects 3 arguments, 1 provided
/usr/include/c++/14/bits/basic_string.h:569:7: note: candidate: 'std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string(const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&, size_type, const _Alloc&) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>; size_type = long unsigned int]'
569 | basic_string(const basic_string& __str, size_type __pos,
| ^~~~~~~~~~~~
/usr/include/c++/14/bits/basic_string.h:569:7: note: candidate expects 3 arguments, 1 provided
/usr/include/c++/14/bits/basic_string.h:552:7: note: candidate: 'std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string(const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]'
552 | basic_string(const basic_string& __str)
| ^~~~~~~~~~~~
/usr/include/c++/14/bits/basic_string.h:552:40: note: no known conversion for argument 1 from 'int' to 'const std::__cxx11::basic_string<char>&'
552 | basic_string(const basic_string& __str)
| ~~~~~~~~~~~~~~~~~~~~^~~~~
/usr/include/c++/14/bits/basic_string.h:540:7: note: candidate: 'std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string(const _Alloc&) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]'
540 | basic_string(const _Alloc& __a) _GLIBCXX_NOEXCEPT
| ^~~~~~~~~~~~
/usr/include/c++/14/bits/basic_string.h:540:34: note: no known conversion for argument 1 from 'int' to 'const std::allocator<char>&'
540 | basic_string(const _Alloc& __a) _GLIBCXX_NOEXCEPT
| ~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/basic_string.h:527:7: note: candidate: 'std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string() [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]'
527 | basic_string()
| ^~~~~~~~~~~~
/usr/include/c++/14/bits/basic_string.h:527:7: note: candidate expects 0 arguments, 1 provided
/us |
s123007838 | p03800 | C++ | #include <iostream>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
char *search(char a, char b, char *s, int N) {
char *ans = (char *)malloc(N + 2);
ans[0] = a;
ans[1] = b;
for (int i = 0; i < N - 1; i++) {
if (s[i + 1] == 'o' && ans[i + 1] == 'S') {
ans[i + 2] = ans[i];
} else if (s[i + 1] == 'x' && ans[i + 1] == 'W') {
ans[i + 2] = ans[i];
} else {
if (ans[i] == 'S') {
ans[i + 2] = 'W';
} else {
ans[i + 2] = 'S';
}
}
}
if (s[0] == 'o' && ans[0] == 'S') {
ans[N + 1] = ans[1];
} else if (s[0] == 'x' && ans[0] == 'W') {
ans[N + 1] = ans[1];
} else {
if (ans[1] == 'S') {
ans[N + 1] = 'W';
} else {
ans[N+1] = 'S';
}
}
if (ans[N-1] == ans[N + 1] && ans[0] == a[N]) {
ans[N] = '\0';
ans[N + 1] = '\0';
return ans;
} else {
return NULL;
}
free(ans);
}
int main() {
int N;
char *s = (char *)malloc(N + 1);
cin >> N >> s;
char *epoch0 = search('S', 'S', s, N);
// char *epoch1 = search('S', 'W', s, N);
// char *epoch2 = search('W', 'S', s, N);
// char *epoch3 = search('W', 'W', s, N);
if (epoch0 != NULL) {
cout << epoch0 << endl;
} else {
free(epoch0);
char *epoch1 = search('S', 'W', s, N);
if (epoch1 != NULL) {
cout << epoch1 << endl;
} else {
free(epoch1);
char *epoch2 = search('W', 'S', s, N);
if (epoch2 != NULL) {
cout << epoch2 << endl;
} else {
free(epoch2);
char *epoch3 = search('W', 'W', s, N);
if (epoch3 != NULL) {
cout << epoch2 << endl;
} else {
free(epoch3);
cout << -1 << endl;
}
}
}
}
return 0;
}
| a.cc: In function 'char* search(char, char, char*, int)':
a.cc:35:44: error: invalid types 'char[int]' for array subscript
35 | if (ans[N-1] == ans[N + 1] && ans[0] == a[N]) {
| ^
a.cc:42:7: warning: control reaches end of non-void function [-Wreturn-type]
42 | free(ans);
| ~~~~^~~~~
|
s649110095 | p03800 | C++ | #include <iostream>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
char *search(char a, char b, char *s, int N) {
char *ans = (char *)malloc(N + 2);
ans[0] = a;
ans[1] = b;
for (int i = 0; i < N - 1; i++) {
if (s[i + 1] == 'o' && ans[i + 1] == 'S') {
ans[i + 2] = ans[i];
} else if (s[i + 1] == 'x' && ans[i + 1] == 'W') {
ans[i + 2] = ans[i];
} else {
if (ans[i] == 'S') {
ans[i + 2] = 'W';
} else {
ans[i + 2] = 'S';
}
}
}
if (s[0] == 'o' && ans[0] == 'S') {
ans[N + 1] = ans[1];
} else if (s[0] == 'x' && ans[0] == 'W') {
ans[N + 1] = ans[1];
} else {
if (ans[1] == 'S') {
ans[N + 1] = 'W';
} else {
ans[N; !] = 'S';
}
}
if (ans[N - 1] == ans[N + 1] && ans[0] == a[N]) {
ans[N] = '\0';
ans[N + 1] = '\0';
return ans;
} else {
return NULL;
}
free(ans);
}
int main() {
int N;
char *s = (char *)malloc(N + 1);
cin >> N >> s;
char *epoch0 = search('S', 'S', s, N);
// char *epoch1 = search('S', 'W', s, N);
// char *epoch2 = search('W', 'S', s, N);
// char *epoch3 = search('W', 'W', s, N);
if (epoch0 != NULL) {
cout << epoch0 << endl;
} else {
free(epoch0);
char *epoch1 = search('S', 'W', s, N);
if (epoch1 != NULL) {
cout << epoch1 << endl;
} else {
free(epoch1);
char *epoch2 = search('W', 'S', s, N);
if (epoch2 != NULL) {
cout << epoch2 << endl;
} else {
free(epoch2);
char *epoch3 = search('W', 'W', s, N);
if (epoch3 != NULL) {
cout << epoch2 << endl;
} else {
free(epoch3);
cout << -1 << endl;
}
}
}
}
return 0;
}
| a.cc: In function 'char* search(char, char, char*, int)':
a.cc:32:12: error: expected ']' before ';' token
32 | ans[N; !] = 'S';
| ^
| ]
a.cc:32:15: error: expected primary-expression before ']' token
32 | ans[N; !] = 'S';
| ^
a.cc:35:46: error: invalid types 'char[int]' for array subscript
35 | if (ans[N - 1] == ans[N + 1] && ans[0] == a[N]) {
| ^
a.cc:42:7: warning: control reaches end of non-void function [-Wreturn-type]
42 | free(ans);
| ~~~~^~~~~
|
s312018189 | p03800 | C++ | Snuke, who loves animals, built a zoo.
There are N animals in this zoo. They are conveniently numbered 1 through N, and arranged in a circle. The animal numbered i(2≤i≤N−1) is adjacent to the animals numbered i−1 and i+1. Also, the animal numbered 1 is adjacent to the animals numbered 2 and N, and the animal numbered N is adjacent to the animals numbered N−1 and 1.
There are two kinds of animals in this zoo: honest sheep that only speak the truth, and lying wolves that only tell lies.
Snuke cannot tell the difference between these two species, and asked each animal the following question: "Are your neighbors of the same species?" The animal numbered i answered si. Here, if si is o, the animal said that the two neighboring animals are of the same species, and if si is x, the animal said that the two neighboring animals are of different species.
More formally, a sheep answered o if the two neighboring animals are both sheep or both wolves, and answered x otherwise. Similarly, a wolf answered x if the two neighboring animals are both sheep or both wolves, and answered o otherwise.
Snuke is wondering whether there is a valid assignment of species to the animals that is consistent with these responses. If there is such an assignment, show one such assignment. Otherwise, print -1. | a.cc:2:126: error: extended character ≤ is not valid in an identifier
2 | There are N animals in this zoo. They are conveniently numbered 1 through N, and arranged in a circle. The animal numbered i(2≤i≤N−1) is adjacent to the animals numbered i−1 and i+1. Also, the animal numbered 1 is adjacent to the animals numbered 2 and N, and the animal numbered N is adjacent to the animals numbered N−1 and 1.
| ^
a.cc:2:126: error: extended character ≤ is not valid in an identifier
a.cc:2:126: error: extended character − is not valid in an identifier
a.cc:2:171: error: extended character − is not valid in an identifier
2 | There are N animals in this zoo. They are conveniently numbered 1 through N, and arranged in a circle. The animal numbered i(2≤i≤N−1) is adjacent to the animals numbered i−1 and i+1. Also, the animal numbered 1 is adjacent to the animals numbered 2 and N, and the animal numbered N is adjacent to the animals numbered N−1 and 1.
| ^
a.cc:2:319: error: extended character − is not valid in an identifier
2 | There are N animals in this zoo. They are conveniently numbered 1 through N, and arranged in a circle. The animal numbered i(2≤i≤N−1) is adjacent to the animals numbered i−1 and i+1. Also, the animal numbered 1 is adjacent to the animals numbered 2 and N, and the animal numbered N is adjacent to the animals numbered N−1 and 1.
| ^
a.cc:1:1: error: 'Snuke' does not name a type
1 | Snuke, who loves animals, built a zoo.
| ^~~~~
|
s190345124 | p03800 | C++ | dsad | a.cc:1:1: error: 'dsad' does not name a type
1 | dsad
| ^~~~
|
s196796811 | p03800 | C++ | #include <bits/stdc++.h>
using namespace std;
//#define FILE_IO
int N;
char s[100005];
int v[100005];
int main()
{
#ifdef FILE_IO
freopen("1.in", "r", stdin);
freopen("1.out", "w", stdout);
#endif
scanf("%d\n", &N);
gets(s + 1);
for(int i = 1; i <= N; i++)
{
if(s[i] == 'o')
s[i] = 0;
else
s[i] = 1;
}
for(v[1] = 0; v[1] <= 1; v[1]++)
for(v[2] = 0; v[2] <= 1; v[2]++)
{
for(int i = 2; i < N; i++)
v[i + 1] = v[i] ^ v[i - 1] ^ s[i];
if(v[1] == v[N] ^ v[N - 1] ^ s[N] && v[N] == v[1] ^ v[2] ^ s[1])
{
for(int i = 1; i <= N; i++)
{
if(v[i] == 0)
printf("S");
else
printf("W");
}
return 0;
}
}
printf("-1\n");
return 0;
}
| a.cc: In function 'int main()':
a.cc:19:5: error: 'gets' was not declared in this scope; did you mean 'getw'?
19 | gets(s + 1);
| ^~~~
| getw
|
s704617733 | p03800 | C++ | #include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(int)(b);i++)
#define rep(i,b) FOR(i,0,b)
typedef long long ll;
const int SIZE=5+1e6;
const int INF=10+1e9;
ll n;
bool issure(bool x[SIZE]){
rep(i,n){
if(x[i]==A[i]) if(x[(i+1)%n]!=x[(i-1+n)%n])return false;
if(x[i]!=A[i]) if(x[(i+1)%n]==x[(i-1+n)%n])return false;
}
return false;
}
int main(){
cin>>n;
string s;
cin>>s;
for(int i=0;i<n;i++){
A[i]=s[i]='o';
}
bool answer = false;
for(int i=0;i<4;i++){
ans[0]= dx[i];
ans[1]= dy[i];
FOR(j,2,n){
if(ans[j-1]==A[j-1])ans[j]=ans[j-2];
else ans[j]=!ans[j-2];
}
if(issure(ans)){
rep(j,n)
cout<<(ans[j]?'S':'W');
cout<<endl;
return 0;
}
}
cout<<-1<<endl;
return 0;
}
| a.cc: In function 'bool issure(bool*)':
a.cc:13:14: error: 'A' was not declared in this scope
13 | if(x[i]==A[i]) if(x[(i+1)%n]!=x[(i-1+n)%n])return false;
| ^
a.cc:14:14: error: 'A' was not declared in this scope
14 | if(x[i]!=A[i]) if(x[(i+1)%n]==x[(i-1+n)%n])return false;
| ^
a.cc: In function 'int main()':
a.cc:24:5: error: 'A' was not declared in this scope
24 | A[i]=s[i]='o';
| ^
a.cc:28:5: error: 'ans' was not declared in this scope; did you mean 'abs'?
28 | ans[0]= dx[i];
| ^~~
| abs
a.cc:28:13: error: 'dx' was not declared in this scope
28 | ans[0]= dx[i];
| ^~
a.cc:29:13: error: 'dy' was not declared in this scope
29 | ans[1]= dy[i];
| ^~
a.cc:31:20: error: 'A' was not declared in this scope
31 | if(ans[j-1]==A[j-1])ans[j]=ans[j-2];
| ^
|
s767088763 | p03800 | C | i,n;char a[100002],s[999999];f(x,y){*a=x;a[1]=y;for(i=0;++i<=n;)a[i+1]=a[i]==87^a[i-1]==87^s[i]=='o'?83:87;if(!strncmp(a,a+n,2))a[n]=0,puts(a),exit(0);} main(){scanf("%d%s",&n,&s);strncat(s,s,n);f(83,83);f(83,87);f(W,83);f(W,W);puts("-1");} | main.c:1:1: warning: data definition has no type or storage class
1 | i,n;char a[100002],s[999999];f(x,y){*a=x;a[1]=y;for(i=0;++i<=n;)a[i+1]=a[i]==87^a[i-1]==87^s[i]=='o'?83:87;if(!strncmp(a,a+n,2))a[n]=0,puts(a),exit(0);} main(){scanf("%d%s",&n,&s);strncat(s,s,n);f(83,83);f(83,87);f(W,83);f(W,W);puts("-1");}
| ^
main.c:1:1: error: type defaults to 'int' in declaration of 'i' [-Wimplicit-int]
main.c:1:3: error: type defaults to 'int' in declaration of 'n' [-Wimplicit-int]
1 | i,n;char a[100002],s[999999];f(x,y){*a=x;a[1]=y;for(i=0;++i<=n;)a[i+1]=a[i]==87^a[i-1]==87^s[i]=='o'?83:87;if(!strncmp(a,a+n,2))a[n]=0,puts(a),exit(0);} main(){scanf("%d%s",&n,&s);strncat(s,s,n);f(83,83);f(83,87);f(W,83);f(W,W);puts("-1");}
| ^
main.c:1:30: error: return type defaults to 'int' [-Wimplicit-int]
1 | i,n;char a[100002],s[999999];f(x,y){*a=x;a[1]=y;for(i=0;++i<=n;)a[i+1]=a[i]==87^a[i-1]==87^s[i]=='o'?83:87;if(!strncmp(a,a+n,2))a[n]=0,puts(a),exit(0);} main(){scanf("%d%s",&n,&s);strncat(s,s,n);f(83,83);f(83,87);f(W,83);f(W,W);puts("-1");}
| ^
main.c: In function 'f':
main.c:1:30: error: type of 'x' defaults to 'int' [-Wimplicit-int]
main.c:1:30: error: type of 'y' defaults to 'int' [-Wimplicit-int]
main.c:1:112: error: implicit declaration of function 'strncmp' [-Wimplicit-function-declaration]
1 | i,n;char a[100002],s[999999];f(x,y){*a=x;a[1]=y;for(i=0;++i<=n;)a[i+1]=a[i]==87^a[i-1]==87^s[i]=='o'?83:87;if(!strncmp(a,a+n,2))a[n]=0,puts(a),exit(0);} main(){scanf("%d%s",&n,&s);strncat(s,s,n);f(83,83);f(83,87);f(W,83);f(W,W);puts("-1");}
| ^~~~~~~
main.c:1:1: note: include '<string.h>' or provide a declaration of 'strncmp'
+++ |+#include <string.h>
1 | i,n;char a[100002],s[999999];f(x,y){*a=x;a[1]=y;for(i=0;++i<=n;)a[i+1]=a[i]==87^a[i-1]==87^s[i]=='o'?83:87;if(!strncmp(a,a+n,2))a[n]=0,puts(a),exit(0);} main(){scanf("%d%s",&n,&s);strncat(s,s,n);f(83,83);f(83,87);f(W,83);f(W,W);puts("-1");}
main.c:1:126: warning: 'strncmp' argument 3 type is 'int' where 'long unsigned int' is expected in a call to built-in function declared without prototype [-Wbuiltin-declaration-mismatch]
1 | i,n;char a[100002],s[999999];f(x,y){*a=x;a[1]=y;for(i=0;++i<=n;)a[i+1]=a[i]==87^a[i-1]==87^s[i]=='o'?83:87;if(!strncmp(a,a+n,2))a[n]=0,puts(a),exit(0);} main(){scanf("%d%s",&n,&s);strncat(s,s,n);f(83,83);f(83,87);f(W,83);f(W,W);puts("-1");}
| ^
<built-in>: note: built-in 'strncmp' declared here
main.c:1:136: error: implicit declaration of function 'puts' [-Wimplicit-function-declaration]
1 | i,n;char a[100002],s[999999];f(x,y){*a=x;a[1]=y;for(i=0;++i<=n;)a[i+1]=a[i]==87^a[i-1]==87^s[i]=='o'?83:87;if(!strncmp(a,a+n,2))a[n]=0,puts(a),exit(0);} main(){scanf("%d%s",&n,&s);strncat(s,s,n);f(83,83);f(83,87);f(W,83);f(W,W);puts("-1");}
| ^~~~
main.c:1:1: note: include '<stdio.h>' or provide a declaration of 'puts'
+++ |+#include <stdio.h>
1 | i,n;char a[100002],s[999999];f(x,y){*a=x;a[1]=y;for(i=0;++i<=n;)a[i+1]=a[i]==87^a[i-1]==87^s[i]=='o'?83:87;if(!strncmp(a,a+n,2))a[n]=0,puts(a),exit(0);} main(){scanf("%d%s",&n,&s);strncat(s,s,n);f(83,83);f(83,87);f(W,83);f(W,W);puts("-1");}
main.c:1:144: error: implicit declaration of function 'exit' [-Wimplicit-function-declaration]
1 | i,n;char a[100002],s[999999];f(x,y){*a=x;a[1]=y;for(i=0;++i<=n;)a[i+1]=a[i]==87^a[i-1]==87^s[i]=='o'?83:87;if(!strncmp(a,a+n,2))a[n]=0,puts(a),exit(0);} main(){scanf("%d%s",&n,&s);strncat(s,s,n);f(83,83);f(83,87);f(W,83);f(W,W);puts("-1");}
| ^~~~
main.c:1:1: note: include '<stdlib.h>' or provide a declaration of 'exit'
+++ |+#include <stdlib.h>
1 | i,n;char a[100002],s[999999];f(x,y){*a=x;a[1]=y;for(i=0;++i<=n;)a[i+1]=a[i]==87^a[i-1]==87^s[i]=='o'?83:87;if(!strncmp(a,a+n,2))a[n]=0,puts(a),exit(0);} main(){scanf("%d%s",&n,&s);strncat(s,s,n);f(83,83);f(83,87);f(W,83);f(W,W);puts("-1");}
main.c:1:144: warning: incompatible implicit declaration of built-in function 'exit' [-Wbuiltin-declaration-mismatch]
1 | i,n;char a[100002],s[999999];f(x,y){*a=x;a[1]=y;for(i=0;++i<=n;)a[i+1]=a[i]==87^a[i-1]==87^s[i]=='o'?83:87;if(!strncmp(a,a+n,2))a[n]=0,puts(a),exit(0);} main(){scanf("%d%s",&n,&s);strncat(s,s,n);f(83,83);f(83,87);f(W,83);f(W,W);puts("-1");}
| ^~~~
main.c:1:144: note: include '<stdlib.h>' or provide a declaration of 'exit'
main.c: At top level:
main.c:1:154: error: return type defaults to 'int' [-Wimplicit-int]
1 | i,n;char a[100002],s[999999];f(x,y){*a=x;a[1]=y;for(i=0;++i<=n;)a[i+1]=a[i]==87^a[i-1]==87^s[i]=='o'?83:87;if(!strncmp(a,a+n,2))a[n]=0,puts(a),exit(0);} main(){scanf("%d%s",&n,&s);strncat(s,s,n);f(83,83);f(83,87);f(W,83);f(W,W);puts("-1");}
| ^~~~
main.c: In function 'main':
main.c:1:161: error: implicit declaration of function 'scanf' [-Wimplicit-function-declaration]
1 | i,n;char a[100002],s[999999];f(x,y){*a=x;a[1]=y;for(i=0;++i<=n;)a[i+1]=a[i]==87^a[i-1]==87^s[i]=='o'?83:87;if(!strncmp(a,a+n,2))a[n]=0,puts(a),exit(0);} main(){scanf("%d%s",&n,&s);strncat(s,s,n);f(83,83);f(83,87);f(W,83);f(W,W);puts("-1");}
| ^~~~~
main.c:1:161: note: include '<stdio.h>' or provide a declaration of 'scanf'
main.c:1:161: warning: incompatible implicit declaration of built-in function 'scanf' [-Wbuiltin-declaration-mismatch]
main.c:1:161: note: include '<stdio.h>' or provide a declaration of 'scanf'
main.c:1:181: error: implicit declaration of function 'strncat' [-Wimplicit-function-declaration]
1 | i,n;char a[100002],s[999999];f(x,y){*a=x;a[1]=y;for(i=0;++i<=n;)a[i+1]=a[i]==87^a[i-1]==87^s[i]=='o'?83:87;if(!strncmp(a,a+n,2))a[n]=0,puts(a),exit(0);} main(){scanf("%d%s",&n,&s);strncat(s,s,n);f(83,83);f(83,87);f(W,83);f(W,W);puts("-1");}
| ^~~~~~~
main.c:1:181: note: include '<string.h>' or provide a declaration of 'strncat'
main.c:1:181: warning: incompatible implicit declaration of built-in function 'strncat' [-Wbuiltin-declaration-mismatch]
main.c:1:181: note: include '<string.h>' or provide a declaration of 'strncat'
main.c:1:216: error: 'W' undeclared (first use in this function)
1 | i,n;char a[100002],s[999999];f(x,y){*a=x;a[1]=y;for(i=0;++i<=n;)a[i+1]=a[i]==87^a[i-1]==87^s[i]=='o'?83:87;if(!strncmp(a,a+n,2))a[n]=0,puts(a),exit(0);} main(){scanf("%d%s",&n,&s);strncat(s,s,n);f(83,83);f(83,87);f(W,83);f(W,W);puts("-1");}
| ^
main.c:1:216: note: each undeclared identifier is reported only once for each function it appears in
|
s205516603 | p03800 | Java | import java.util.Arrays;
import java.util.Scanner;
public class MainD {
MyScanner sc = new MyScanner();
Scanner sc2 = new Scanner(System.in);
long start = System.currentTimeMillis();
long fin = System.currentTimeMillis();
final int MOD = 1000000007;
int[] dx = { 1, 0, 0, -1 };
int[] dy = { 0, 1, -1, 0 };
void run() {
int n = sc.nextInt();
char[] c = sc.next().toCharArray();
String[] f = { "SS", "SW", "WS", "WW" };
StringBuilder s = new StringBuilder();
for (int i = 0; i < 4; i++) {
for (int j = 0; j < n; j++) {
if (j == 0 || j == 1) {
s.append(f[i].charAt(j));
} else {
if (s.charAt(j - 1) == 'S') {
if (c[j - 1] == 'o')
s.append(s.charAt(j - 2));
else
s.append(s.charAt(j - 2) == 'S' ? 'W' : 'S');
} else {
if (c[j - 1] == 'o')
s.append(s.charAt(j - 2) == 'S' ? 'W' : 'S');
else
s.append(s.charAt(j - 2));
}
}
}
if (ok(n, c, s)) {
System.out.println(s);
return;
}
s.setLength(0);
}
System.out.println(-1);
}
boolean ok(int n, char[] c, StringBuilder s) {
String ss = s.toString() + s.toString();
for (int i = 1; i < n * 2 - 1; i++) {
if (ss.charAt(i) == 'S') {
if (c[i % n] == 'o' && !(ss.charAt(i - 1) == ss.charAt(i + 1)))
return false;
else if (c[i % n] == 'x' && !(ss.charAt(i - 1) != ss.charAt(i + 1)))
return false;
} else {
if (c[i % n] == 'o' && !(ss.charAt(i - 1) != ss.charAt(i + 1)))
return false;
else if (c[i % n] == 'x' && !(ss.charAt(i - 1) == ss.charAt(i + 1)))
return false;
}
}
return true;
}
public static void main(String[] args) {
new MainD().run();
}
void debug(Object... o) {
System.out.println(Arrays.deepToString(o));
}
void debug2(int[][] array) {
for (int i = 0; i < array.length; i++) {
for (int j = 0; j < array[i].length; j++) {
System.out.print(array[i][j]);
}
System.out.println();
}
}
boolean inner(int h, int w, int limH, int limW) {
return 0 <= h && h < limH && 0 <= w && w < limW;
}
void swap(int[] x, int a, int b) {
int tmp = x[a];
x[a] = x[b];
x[b] = tmp;
}
// find minimum i (k <= a[i])
int lower_bound(int a[], int k) {
int l = -1;
int r = a.length;
while (r - l > 1) {
int mid = (l + r) / 2;
if (k <= a[mid])
r = mid;
else
l = mid;
}
// r = l + 1
return r;
}
// find minimum i (k < a[i])
int upper_bound(int a[], int k) {
int l = -1;
int r = a.length;
while (r - l > 1) {
int mid = (l + r) / 2;
if (k < a[mid])
r = mid;
else
l = mid;
}
// r = l + 1
return r;
}
int gcd(int a, int b) {
return a % b == 0 ? b : gcd(b, a % b);
}
int lcm(int a, int b) {
return a * b / gcd(a, b);
}
boolean palindrome(String s) {
for (int i = 0; i < s.length() / 2; i++) {
if (s.charAt(i) != s.charAt(s.length() - 1 - i)) {
return false;
}
}
return true;
}
class MyScanner {
int nextInt() {
try {
int c = System.in.read();
while (c != '-' && (c < '0' || '9' < c))
c = System.in.read();
if (c == '-')
return -nextInt();
int res = 0;
do {
res *= 10;
res += c - '0';
c = System.in.read();
} while ('0' <= c && c <= '9');
return res;
} catch (Exception e) {
return -1;
}
}
double nextDouble() {
return Double.parseDouble(next());
}
long nextLong() {
return Long.parseLong(next());
}
String next() {
try {
StringBuilder res = new StringBuilder("");
int c = System.in.read();
while (Character.isWhitespace(c))
c = System.in.read();
do {
res.append((char) c);
} while (!Character.isWhitespace(c = System.in.read()));
return res.toString();
} catch (Exception e) {
return null;
}
}
int[] nextIntArray(int n) {
int[] in = new int[n];
for (int i = 0; i < n; i++) {
in[i] = nextInt();
}
return in;
}
int[][] nextInt2dArray(int n, int m) {
int[][] in = new int[n][m];
for (int i = 0; i < n; i++) {
in[i] = nextIntArray(m);
}
return in;
}
double[] nextDoubleArray(int n) {
double[] in = new double[n];
for (int i = 0; i < n; i++) {
in[i] = nextDouble();
}
return in;
}
long[] nextLongArray(int n) {
long[] in = new long[n];
for (int i = 0; i < n; i++) {
in[i] = nextLong();
}
return in;
}
char[][] nextCharField(int n, int m) {
char[][] in = new char[n][m];
for (int i = 0; i < n; i++) {
String s = sc.next();
for (int j = 0; j < m; j++) {
in[i][j] = s.charAt(j);
}
}
return in;
}
}
} | Main.java:4: error: class MainD is public, should be declared in a file named MainD.java
public class MainD {
^
1 error
|
s264206454 | p03800 | C++ | #include <bits/stdc++.h>
using namespace std;
#define int long long
using ll=long long;
using vi=vector<int>;
using vl=vector<long long>;
using pii=pair<int,int>;
using pll=pair<long long,long long>;
#define ITR(i,c) for(auto i=begin(c);i!=end(c);++i)
#define FORE(x,c) for(auto &x:c)
#define FOR(i,a,n) for(int i=a,i##_len=(int)n;i<i##_len;++i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i=((int)(n)-1);i>=0;--i)
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c) // c++14
#define SZ(c) ((int)c.size())
#define dump(...)
const int DX[9]={0,1,0,-1,1,1,-1,-1,0}, DY[9]={-1,0,1,0,-1,1,1,-1,0};
const int INF=1001001001; const long long INFLL=1001001001001001001ll;
template<class T> ostream& operator << (ostream &os, const vector<T> &v) {
ITR(i,v) os << *i << (i==end(v)-1 ? "" : " "); return os; }
template<class T> istream& operator >> (istream &is, vector<T> &v) {
ITR(i,v) is >> * i; return is; }
template<class T> istream& operator >> (istream &is, pair<T,T> &p) {
is >> p.first >> p.second; return is; }
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
//------------------------------------------------------------------------------
struct before_main_function {
before_main_function() {
#ifdef int
cerr<<"\x1b[7m"<<"'int' is defined as 'long long' !!!!"<<"\x1b[m"<<endl;
#endif
cin.tie(0);ios::sync_with_stdio(false);
cout<<setprecision(12)<<fixed;
}
} before_main_function;
//------------------------------------------------------------------------------
int n;
string s;
const bool S=true;
const bool W=false;
bool hoge(vector<bool> &t) {
int ret=0;
FOR(i,1,n) {
if(i!=n-1) {
if(t[i]==S) {
if(s[i]=='o') {
t.push_back(t[i-1]);
}
else {
t.push_back(!t[i-1]);
}
}
else {
if(s[i]=='o') {
t.push_back(!t[i-1]);
}
else {
t.push_back(t[i-1]);
}
}
}
else {
if(t[i]==S) {
if(s[i]=='o') {
ret=(t[i-1]==t[0]),;
}
else {
ret=(t[i-1]!=t[0]);
}
}
else {
if(s[i]=='o') {
ret=(t[i-1]!=t[0]);
}
else {
ret=([i-1]==t[0]);
}
}
}
}
if(t[0]==S) {
if(s[0]=='o') ret+=(t[n-1]==t[1]);
else ret+=(t[n-1]!=t[1]);
}
else {
if(s[0]=='o') ret+=(t[n-1]!=t[1]);
else ret+=([n-1]==t[1]);
}
return ret==2;
}
string fuga(vector<bool> a) {
string ret="";
for(bool x:a) {
if(x==S) ret+="S";
else ret+="W";
}
return ret;
}
signed main() {
cin>>n>>s;
vector<bool> a={S,S},b={S,W},c={W,S},d={W,W};
/* */ if(hoge(a)) cout<<fuga(a)<<endl;
else if(hoge(b)) cout<<fuga(b)<<endl;
else if(hoge(c)) cout<<fuga(c)<<endl;
else if(hoge(d)) cout<<fuga(d)<<endl;
else cout<<-1<<endl;
return 0;
}
| a.cc: In function 'bool hoge(std::vector<bool>&)':
a.cc:67:40: error: expected primary-expression before ';' token
67 | ret=(t[i-1]==t[0]),;
| ^
a.cc:78:28: error: expected ',' before '-' token
78 | ret=([i-1]==t[0]);
| ^
| ,
a.cc:78:28: error: expected identifier before '-' token
a.cc: In lambda function:
a.cc:78:31: error: expected '{' before '==' token
78 | ret=([i-1]==t[0]);
| ^~
a.cc: In function 'bool hoge(std::vector<bool>&)':
a.cc:78:31: error: no match for 'operator==' (operand types are 'hoge(std::vector<bool>&)::<lambda()>' and 'std::vector<bool>::reference')
78 | ret=([i-1]==t[0]);
| ~~~~~^~~~~~
| | |
| | std::vector<bool>::reference
| hoge(std::vector<bool>&)::<lambda()>
In file included from /usr/include/c++/14/regex:68,
from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:181,
from a.cc:1:
/usr/include/c++/14/bits/regex.h:1103:5: note: candidate: 'template<class _BiIter> bool std::__cxx11::operator==(const sub_match<_BiIter>&, const sub_match<_BiIter>&)'
1103 | operator==(const sub_match<_BiIter>& __lhs, const sub_match<_BiIter>& __rhs)
| ^~~~~~~~
/usr/include/c++/14/bits/regex.h:1103:5: note: template argument deduction/substitution failed:
a.cc:78:36: note: 'hoge(std::vector<bool>&)::<lambda()>' is not derived from 'const std::__cxx11::sub_match<_BiIter>'
78 | ret=([i-1]==t[0]);
| ^
/usr/include/c++/14/bits/regex.h:1199:5: note: candidate: 'template<class _Bi_iter, class _Ch_traits, class _Ch_alloc> bool std::__cxx11::operator==(__sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>&, const sub_match<_BiIter>&)'
1199 | operator==(const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __lhs,
| ^~~~~~~~
/usr/include/c++/14/bits/regex.h:1199:5: note: template argument deduction/substitution failed:
a.cc:78:36: note: 'hoge(std::vector<bool>&)::<lambda()>' is not derived from 'std::__cxx11::__sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>'
78 | ret=([i-1]==t[0]);
| ^
/usr/include/c++/14/bits/regex.h:1274:5: note: candidate: 'template<class _Bi_iter, class _Ch_traits, class _Ch_alloc> bool std::__cxx11::operator==(const sub_match<_BiIter>&, __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>&)'
1274 | operator==(const sub_match<_Bi_iter>& __lhs,
| ^~~~~~~~
/usr/include/c++/14/bits/regex.h:1274:5: note: template argument deduction/substitution failed:
a.cc:78:36: note: 'hoge(std::vector<bool>&)::<lambda()>' is not derived from 'const std::__cxx11::sub_match<_BiIter>'
78 | ret=([i-1]==t[0]);
| ^
/usr/include/c++/14/bits/regex.h:1366:5: note: candidate: 'template<class _Bi_iter> bool std::__cxx11::operator==(const typename std::iterator_traits<_Iter>::value_type*, const sub_match<_BiIter>&)'
1366 | operator==(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
| ^~~~~~~~
/usr/include/c++/14/bits/regex.h:1366:5: note: template argument deduction/substitution failed:
a.cc:78:36: note: 'std::vector<bool>::reference' is not derived from 'const std::__cxx11::sub_match<_BiIter>'
78 | ret=([i-1]==t[0]);
| ^
/usr/include/c++/14/bits/regex.h:1441:5: note: candidate: 'template<class _Bi_iter> bool std::__cxx11::operator==(const sub_match<_BiIter>&, const typename std::iterator_traits<_Iter>::value_type*)'
1441 | operator==(const sub_match<_Bi_iter>& __lhs,
| ^~~~~~~~
/usr/include/c++/14/bits/regex.h:1441:5: note: template argument deduction/substitution failed:
a.cc:78:36: note: 'hoge(std::vector<bool>&)::<lambda()>' is not derived from 'const std::__cxx11::sub_match<_BiIter>'
78 | ret=([i-1]==t[0]);
| ^
/usr/include/c++/14/bits/regex.h:1534:5: note: candidate: 'template<class _Bi_iter> bool std::__cxx11::operator==(const typename std::iterator_traits<_Iter>::value_type&, const sub_match<_BiIter>&)'
1534 | operator==(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
| ^~~~~~~~
/usr/include/c++/14/bits/regex.h:1534:5: note: template argument deduction/substitution failed:
a.cc:78:36: note: 'std::vector<bool>::reference' is not derived from 'const std::__cxx11::sub_match<_BiIter>'
78 | ret=([i-1]==t[0]);
| ^
/usr/include/c++/14/bits/regex.h:1613:5: note: candidate: 'template<class _Bi_iter> bool std::__cxx11::operator==(const sub_match<_BiIter>&, const typename std::iterator_traits<_Iter>::value_type&)'
1613 | operator==(const sub_match<_Bi_iter>& __lhs,
| ^~~~~~~~
/usr/include/c++/14/bits/regex.h:1613:5: note: template argument deduction/substitution failed:
a.cc:78:36: note: 'hoge(std::vector<bool>&)::<lambda()>' is not derived from 'const std::__cxx11::sub_match<_BiIter>'
78 | ret=([i-1]==t[0]);
| ^
/usr/include/c++/14/bits/regex.h:2186:5: note: candidate: 'template<class _Bi_iter, class _Alloc> bool std::__cxx11::operator==(const match_results<_BiIter, _Alloc>&, const match_results<_BiIter, _Alloc>&)'
2186 | operator==(const match_results<_Bi_iter, _Alloc>& __m1,
| ^~~~~~~~
/usr/include/c++/14/bits/regex.h:2186:5: note: template argument deduction/substitution failed:
a.cc:78:36: note: 'hoge(std::vector<bool>&)::<lambda()>' is not derived from 'const std::__cxx11::match_results<_BiIter, _Alloc>'
78 | ret=([i-1]==t[0]);
| ^
In file included from /usr/include/c++/14/bits/stl_algobase.h:64,
from /usr/include/c++/14/algorithm:60,
from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51:
/usr/include/c++/14/bits/stl_pair.h:1033:5: note: candidate: 'template<class _T1, class _T2> constexpr bool std::operator==(const pair<_T1, _T2>&, const pair<_T1, _T2>&)'
1033 | operator==(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y)
| ^~~~~~~~
/usr/include/c++/14/bits/stl_pair.h:1033:5: note: template argument deduction/substitution failed:
a.cc:78:36: note: 'hoge(std::vector<bool>&)::<lambda()>' is not derived from 'const std::pair<_T1, _T2>'
78 | ret=([i-1]==t[0]);
| ^
In file included from /usr/include/c++/14/bits/stl_algobase.h:67:
/usr/include/c++/14/bits/stl_iterator.h:441:5: note: candidate: 'template<class _Iterator> constexpr bool std::operator==(const reverse_iterator<_Iterator>&, const reverse_iterator<_Iterator>&)'
441 | operator==(const reverse_iterator<_Iterator>& __x,
| ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:441:5: note: template argument deduction/substitution failed:
a.cc:78:36: note: 'hoge(std::vector<bool>&)::<lambda()>' is not derived from 'const std::reverse_iterator<_Iterator>'
78 | ret=([i-1]==t[0]);
| ^
/usr/include/c++/14/bits/stl_iterator.h:486:5: note: candidate: 'template<class _IteratorL, class _IteratorR> constexpr bool std::operator==(const reverse_iterator<_Iterator>&, const reverse_iterator<_IteratorR>&)'
486 | operator==(const reverse_iterator<_IteratorL>& __x,
| ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:486:5: note: template argument deduction/substitution failed:
a.cc:78:36: note: 'hoge(std::vector<bool>&)::<lambda()>' is not derived from 'const std::reverse_iterator<_Iterator>'
78 | ret=([i-1]==t[0]);
| ^
/usr/include/c++/14/bits/stl_iterator.h:1667:5: note: candidate: 'template<class _IteratorL, class _IteratorR> constexpr bool std::operator==(const move_iterator<_IteratorL>&, const move_iterator<_IteratorR>&)'
1667 | operator==(const move_iterator<_IteratorL>& __x,
| ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:1667:5: note: template argument deduction/substitution failed:
a.cc:78:36: note: 'hoge(std::vector<bool>&)::<lambda()>' is not derived from 'const std::move_iterator<_IteratorL>'
78 | ret=([i-1]==t[0]);
| ^
/usr/include/c++/14/bits/stl_iterator.h:1737:5: note: candidate: 'template<class _Iterator> constexpr bool std::operator==(const move_iterator<_IteratorL>&, const move_iterator<_IteratorL>&)'
1737 | operator==(const move_iterator<_Iterator>& __x,
| ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:1737:5: note: template argument deduction/substitution failed:
a.cc:78:36: note: 'hoge(std::vector<bool>&)::<lambda()>' is not derived from 'const std::move_iterator<_IteratorL>'
78 | ret=([i-1]==t[0]);
| ^
In file included from /usr/include/c++/14/bits/char_traits.h:42,
from /usr/include/c++/14/string:42,
from /usr/include/c++/14/bitset:52,
from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52:
/usr/include/c++/14/bits/postypes.h:192:5: note: candidate: 'template<class _StateT> bool std::operator==(const fpos<_StateT>&, const fpos<_StateT>&)'
192 | operator==(const fpos<_StateT>& __lhs, const fpos<_StateT>& __rhs)
| ^~~~~~~~
/usr/include/c++/14/bits/postypes.h:192:5: note: template argument deduction/substitution failed:
a.cc:78:36: note: 'hoge(std::vector<bool>&)::<lambda()>' is not derived from 'const std::fpos<_StateT>'
78 | ret=([i-1]==t[0]);
| ^
In file included from /usr/include/c++/14/string:43:
/usr/include/c++/14/bits/allo |
s046319713 | p03800 | C++ | #include <algorithm>
#include <cmath>
#include <climits>
#include <cstring>
#include <cstdio>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map> //pair is also included in this library
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#define REP(i, s, n) for(int i = (int)(s); i < (int)(n); i++)
#define fst first
#define snd second
#define MP make_pair //incase c++11 or later is not available
using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
//prefer define statement
//for reason that const int ver. of INF will raise a silly warning (unused variable)
#define INF (INT_MAX/3)
#define LIM_INF (INT_MAX)
//const int INF = INT_MAX/3;
#define PI = 3.14159265358979323846
/*------------------------------------------------------------------------------*/
int main(){
int N;
cin >> N;
string s;
cin >> s;
VI ans(N);
//0 -> S, 1 -> W
vector<bool> sample = {0, 0, 0, 1, 1, 0, 1, 1};
int cnt = 0;
bool b = false;
while(cnt < 4){
ans[0] = sample[cnt*2];
ans[1] = sample[cnt*2+1];
REP(i, 2, N){
if(s[i-1] == 'o' && !ans[i-1]){
ans[i] = ans[i-2];
}
if(s[i-1] == 'x' && !ans[i-1]){
ans[i] = !ans[i-2];
}
if(s[i-1] == 'o' && ans[i-1]){
ans[i] = !ans[i-2];
}
if(s[i-1] == 'x' && ans[i-1]){
ans[i] = ans[i-2];
}
}
bool order1 = false//, order2 = false;
if(s[0] == 'o' && !ans[0]){
order1 = ans[1] == ans[N-1];
}
if(s[0] == 'x' && !ans[0]){
order1 = ans[1] == !ans[N-1];
}
if(s[0] == 'o' && ans[0]){
order1 = ans[1] == !ans[N-1];
}
if(s[0] == 'x' && ans[0]){
order1 = ans[1] == ans[N-1];
}
// if(s[N-1] == 'o' && !ans[N-1]){
// order2 = ans[0] == ans[N-2];
// }
// if(s[N-1] == 'x' && !ans[N-1]){
// order2 = ans[0] == !ans[N-2];
// }
// if(s[N-1] == 'o' && ans[N-1]){
// order2 = ans[0] == !ans[N-2];
// }
// if(s[N-1] == 'x' && ans[N-1]){
// order2 = ans[0] == ans[N-2];
// }
if(order1){
b = true;
break;
}
cnt++;
}
if(b){
REP(i, 0, N){
if(ans[i]){
cout << 'W';
} else {
cout << 'S';
}
}
cout << endl;
} else {
cout << -1 << endl;
}
return 0;
}
| a.cc: In function 'int main()':
a.cc:70:5: error: expected ',' or ';' before 'if'
70 | if(s[0] == 'o' && !ans[0]){
| ^~
|
s182046922 | p03800 | C++ | #include<iostream>
#include<string>
#include<vector>
#include<set>
#include<algorithm>
#include<queue>
#include<functional>
#include<numeric>
#include<sstream>
#include<math.h>
#include <iomanip>
#define ll long long
#define PLL pair<ll,ll>
#define VS vector<string>
#define VL vector<ll>
#define rep(i,a) for (ll i=0;i<a;i++)
#define nrep(i,n,a) for (ll i=n;i<a;i++)
#define mrep(i,a) for(ll i=a;i>=0;i--)
#define INF 1145141919810
#define VMIN(vec) *std::max_element(vec.begin(),vec.end())
#define VMIN(vec) *std::max_element(vec.begin(),vec.end())
#define VSUM(vec) std::accumulate(vec.begin(),vec.end(),0LL)
#define LTS(n) to_string(n)
#define STL(str) stoll(str);
using namespace std;
ll n;
string s;
ll prev(ll nn){
if (nn == 0) return n - 1;
return nn - 1;
}
ll next(ll nn){
return (nn + 1) % n;
}
//s_or_w:0->s s_or_w:1->w
bool fun(ll index,ll s_or_w,VL sum,bool first){
if(sum[index]==-1) sum[index] = s_or_w;
else if (!first && sum[index] != -1){
if (sum[index] == s_or_w){
if (s_or_w == 0){
if (s[0] == 'o' && sum[n - 1] == sum[1]){
rep(i, n) cout << (sum[i] == 0 ? "S" : "W");
cout << endl;
return true;
}
else if (s[0] == 'x' && sum[n - 1] != sum[1]){
rep(i, n) cout << (sum[i] == 0 ? "S" : "W");
cout << endl;
return true;
}
else return false;
}
else{
if (s[0] == 'o' && sum[n - 1] != sum[1]){
rep(i, n) cout << (sum[i] == 0 ? "S" : "W");
cout << endl;
return true;
}
else if (sum[0] == 'x' && sum[n - 1] == sum[1]){
rep(i, n) cout << (sum[i] == 0 ? "S" : "W");
cout << endl;
return true;
}
else return false;
}
}
else return false;
}
if (s_or_w == 0){
if (s[index] == 'o'){
return fun((index+1)%n, sum[index-1], sum,false);
}
else{
return fun((index + 1)%n, (sum[index - 1] == 0 ? 1 : 0), sum, false);
}
}
else{
if (s[index] == 'o'){
return fun((index + 1)%n, (sum[index - 1] == 0 ? 1 : 0), sum, false);
}
else{
return fun((index + 1)%n, sum[index - 1], sum, false);
}
}
return false;
}
int main() {
cin >> n;
cin >> s;
VL sum(n, -1);
sum[0] = 0; sum[1] = 0;
if (fun(1, 0, sum, true)) return 0;
VL sum(n,-1);
sum[0] = 1; sum[1] = 0;
if(fun(1, 1, sum, true)) return 0;
VL sum(n, -1);
sum[0] = 1; sum[1] = 1;
if (fun(1, 0, sum, true)) return 0;
VL sum(n, -1);
sum[0] = 0; sum[1] = 1;
if (fun(1, 1, sum, true)) return 0;
cout << -1 << endl;
return 0;
} | a.cc: In function 'int main()':
a.cc:103:12: error: redeclaration of 'std::vector<long long int> sum'
103 | VL sum(n,-1);
| ^~~
a.cc:100:12: note: 'std::vector<long long int> sum' previously declared here
100 | VL sum(n, -1);
| ^~~
a.cc:106:12: error: redeclaration of 'std::vector<long long int> sum'
106 | VL sum(n, -1);
| ^~~
a.cc:100:12: note: 'std::vector<long long int> sum' previously declared here
100 | VL sum(n, -1);
| ^~~
a.cc:109:12: error: redeclaration of 'std::vector<long long int> sum'
109 | VL sum(n, -1);
| ^~~
a.cc:100:12: note: 'std::vector<long long int> sum' previously declared here
100 | VL sum(n, -1);
| ^~~
|
s068604363 | p03800 | C++ | #include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
int main()
{
string line;
getline(cin, line);
const int N = stoi(line);
getline(cin, line);
vector<char> cands = {'S', 'W'};
for(char first : cands)
{
for(char second : cands)
{
vector<char> ans(N);
ans[0] = first;
ans[1] = second;
ans[N - 1] = ((ans[0] == 'S') ^ (line[0] == 'o') ^ (ans[1] == 'S') == true) ? 'S' : 'W';
for(int i = 2; i < N - 1; i++)
{
ans[i] = ((ans[i - 1] == 'S') ^ (line[i - 1] == 'o') ^ (ans[i - 2] == 'S') == true) ? 'S' : 'W';
}
if(((ans[N - 1] == 'S') ^ (line[N - 1] == 'o') ^ (ans[N - 2] == 'S') ^ (ans[0] == 'S')) == false)
{
for(auto ch : ans) cout << ch;
cout << endl;
return 0;
}
}
}
cout << -1 << endl;
}
| a.cc: In function 'int main()':
a.cc:15:3: error: 'vector' was not declared in this scope
15 | vector<char> cands = {'S', 'W'};
| ^~~~~~
a.cc:3:1: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
2 | #include <algorithm>
+++ |+#include <vector>
3 |
a.cc:15:10: error: expected primary-expression before 'char'
15 | vector<char> cands = {'S', 'W'};
| ^~~~
a.cc:16:20: error: 'cands' was not declared in this scope
16 | for(char first : cands)
| ^~~~~
a.cc:20:18: error: expected primary-expression before 'char'
20 | vector<char> ans(N);
| ^~~~
a.cc:21:11: error: 'ans' was not declared in this scope; did you mean 'abs'?
21 | ans[0] = first;
| ^~~
| abs
|
s475088360 | p03800 | C++ | #include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
int main()
{
string line;
getline(cin, line);
const int N = stoi(line);
getline(cin, line);
vector<char> cands = {'S', 'W'};
for(char first : cands)
{
for(char second : cands)
{
vector<char> ans(N);
ans[0] = first;
ans[1] = second;
ans[N - 1] = ((ans[0] == 'S') ^ (line[0] == 'o') ^ (ans[1] == 'S') == true) ? 'S' : 'W';
for(int i = 2; i < N - 1; i++)
{
ans[i] = ((ans[i - 1] == 'S') ^ (line[i - 1] == 'o') ^ (ans[i - 2] == 'S') == true) ? 'S' : 'W';
}
if(((ans[N - 1] == 'S') ^ (line[N - 1] == 'o') ^ (ans[N - 2] == 'S') ^ (ans[0] == 'S')) == false)
{
for(auto ch : ans) cout << ch;
cout << endl;
return 0;
}
// for(auto v : ans) cout << v << ", ";
// cout << endl;
}
}
cout << -1 << endl;
}
| a.cc: In function 'int main()':
a.cc:15:3: error: 'vector' was not declared in this scope
15 | vector<char> cands = {'S', 'W'};
| ^~~~~~
a.cc:3:1: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
2 | #include <algorithm>
+++ |+#include <vector>
3 |
a.cc:15:10: error: expected primary-expression before 'char'
15 | vector<char> cands = {'S', 'W'};
| ^~~~
a.cc:16:20: error: 'cands' was not declared in this scope
16 | for(char first : cands)
| ^~~~~
a.cc:20:18: error: expected primary-expression before 'char'
20 | vector<char> ans(N);
| ^~~~
a.cc:21:11: error: 'ans' was not declared in this scope; did you mean 'abs'?
21 | ans[0] = first;
| ^~~
| abs
|
s433956079 | p03800 | C | #include<cstdio>
using namespace std;
int main(void)
{
//3つの狼の合計が偶数->〇
//S->0 W->1
//S->0x53
//W->0x57
//o->0x6f
//x->0x78
long long int N, i, h, x = 0, ok = 0;
char c;
static char say[100015];
static long long int dou[100015];
long long int sta[2];
scanf("%lld", &N);
fflush(stdin);
for (i = 0; i < N; i++) {
scanf("%c", &say[i]);
}
for (h = 0; h < 4; h++) {
if (h == 0) { sta[0] = 0; sta[1] = 0; }
if (h == 1) { sta[0] = 0; sta[1] = 1; }
if (h == 2) { sta[0] = 1; sta[1] = 0; }
if (h == 3) { sta[0] = 1; sta[1] = 1; }
dou[0] = sta[0];
dou[1] = sta[1];
for (i = 2; i < N + 2; i++) {
if (say[i-1] == 0x6f) { x = 0; }else { x = 1; }
if ((x+dou[i - 1] + dou[i - 2])%2==1) {dou[i] = 1;}else { dou[i] = 0;}
}
if (dou[N] == sta[0] && dou[N + 1] == sta[1]) {
for (i = 1; i <=N; i++) {
if (dou[i] == 0) { c = 0x53; }
else { c = 0x57; }
printf("%c", c);
ok = 1;
}
break;
}
}
if (ok == 0) { printf("-1"); }
printf("\n");
return 0;
}
| main.c:1:9: fatal error: cstdio: No such file or directory
1 | #include<cstdio>
| ^~~~~~~~
compilation terminated.
|
s342267159 | p03800 | C | #include<stdio.h>
int main(void)
{
//3つの狼の合計が偶数->〇
//S->0 W->1
//S->0x53
//W->0x57
//o->0x6f
//x->0x78
long long int N, i, h, x = 0, ok = 0;
char c;
static char say[100015];
static long long int dou[100015];
long long int sta[2];
scanf("%lld", &N);
fflush(stdin);
for (i = 0; i < N; i++) {
scanf("%c", &say[i]);
}
for (h = 0; h < 4; h++) {
if (h == 0) { sta[0] = 0; sta[1] = 0; }
if (h == 1) { sta[0] = 0; sta[1] = 1; }
if (h == 2) { sta[0] = 1; sta[1] = 0; }
if (h == 3) { sta[0] = 1; sta[1] = 1; }
dou[0] = sta[0];
dou[1] = sta[1];
for (i = 2; i < N + 2; i++) {
if (say[i-1] == 0x6f) { x = 0; }else { x = 1; }
if ((x+dou[i - 1] + dou[i - 2])%2==1) {dou[i] = 1;}else { dou[i] = 0;}
}
if (dou[N] == sta[0] && dou[N + 1] == sta[1]) {
for (i = 1; i < =N; i++) {
if (dou[i] == 0) { c = 0x53; }
else { c = 0x57; }
printf("%c", c);
ok = 1;
}
break;
}
}
if (ok == 0) { printf("-1"); }
printf("\n");
return 0;
}
| main.c: In function 'main':
main.c:32:41: error: expected expression before '=' token
32 | for (i = 1; i < =N; i++) {
| ^
|
s712392207 | p03800 | C++ | #include <iostream>
#include <string>
#include <cstdint>
using namespace std;
char next(char before, char now, char ans)
{
auto inv = [](char animalType){ return animalType == 'S' ? 'W' : 'S'; };
char result{ before };
if(ans != 'o') {
result = inv(result);
}
if(now != 'S') {
result = inv(result);
}
return result;
}
bool judge(string& str, string ans)
{
for(auto i = 1; i < str.size() - 1; ++i) {
str[i + 1] = next(str[i - 1], str[i], ans[i]);
}
return str[0] == str.back();
}
int main()
{
int_least32_t n;
cin >> n;
string input;
cin >> input;
string result(n + 1, 'S');
char ini[2] = { 'S', 'W' };
bool flag{ false };
for(auto i = 0; i < 2 && flag == false; ++i) {
result[0] = ini[i];
for(auto j = 0; j < 2 && flag == false; ++j) {
result[1] = ini[j];
flag = judge(result, ans);
}
}
if(flag) {
cout << result << endl;
}
else {
cout << -1 << endl;
}
}
| a.cc: In function 'int main()':
a.cc:47:46: error: 'ans' was not declared in this scope; did you mean 'abs'?
47 | flag = judge(result, ans);
| ^~~
| abs
|
s041172746 | p03800 | C++ | #include <iostream>
#include <string>
#include <cstdint>
using namespace std;
char next(char before, char now, char ans)
{
auto inv = [](char animalType){ return animalType == 'S' ? 'W' : 'S'; };
char result{ before };
if(ans != 'o') {
result = inv(result);
}
if(now != 'S') {
result = inv(result);
}
return result;
}
bool judge(string& str, string ans)
{
for(auto i = 1; i < str.size() - 1; ++i) {
str[i + 1] = next(str[i - 1], str[i], ans[i]);
}
return str[0] == str.back();
}
int main()
{
int_least32_t n;
cin >> n;
string input;
cin >> input;
string result(n + 1);
char ini[2] = { 'S', 'W' };
bool flag{ false };
for(auto i = 0; i < 2 && flag == false; ++i) {
result[0] = ini[i];
for(auto j = 0; j < 2 && flag == false; ++j) {
result[1] = ini[j];
flag = judge(result, ans);
}
}
if(flag) {
cout << result << endl;
}
else {
cout << -1 << endl;
}
}
| a.cc: In function 'int main()':
a.cc:40:28: error: no matching function for call to 'std::__cxx11::basic_string<char>::basic_string(int_least32_t)'
40 | string result(n + 1);
| ^
In file included from /usr/include/c++/14/string:54,
from /usr/include/c++/14/bits/locale_classes.h:40,
from /usr/include/c++/14/bits/ios_base.h:41,
from /usr/include/c++/14/ios:44,
from /usr/include/c++/14/ostream:40,
from /usr/include/c++/14/iostream:41,
from a.cc:1:
/usr/include/c++/14/bits/basic_string.h:800:9: note: candidate: 'template<class _Tp, class> std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string(const _Tp&, const _Alloc&) [with <template-parameter-2-2> = _Tp; _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]'
800 | basic_string(const _Tp& __t, const _Alloc& __a = _Alloc())
| ^~~~~~~~~~~~
/usr/include/c++/14/bits/basic_string.h:800:9: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/14/bits/move.h:37,
from /usr/include/c++/14/bits/exception_ptr.h:41,
from /usr/include/c++/14/exception:166,
from /usr/include/c++/14/ios:41:
/usr/include/c++/14/type_traits: In substitution of 'template<bool _Cond, class _Tp> using std::enable_if_t = typename std::enable_if::type [with bool _Cond = false; _Tp = void]':
/usr/include/c++/14/bits/basic_string.h:149:8: required by substitution of 'template<class _CharT, class _Traits, class _Alloc> template<class _Tp, class _Res> using std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::_If_sv = std::enable_if_t<((bool)std::__and_<std::is_convertible<const _Tp&, std::basic_string_view<_CharT, _Traits> >, std::__not_<std::is_convertible<const _Tp*, const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>*> >, std::__not_<std::is_convertible<const _Tp&, const _CharT*> > >::value), _Res> [with _Tp = int; _Res = void; _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]'
149 | using _If_sv = enable_if_t<
| ^~~~~~
/usr/include/c++/14/bits/basic_string.h:797:30: required from here
797 | template<typename _Tp, typename = _If_sv<_Tp, void>>
| ^~~~~~~~
/usr/include/c++/14/type_traits:2711:11: error: no type named 'type' in 'struct std::enable_if<false, void>'
2711 | using enable_if_t = typename enable_if<_Cond, _Tp>::type;
| ^~~~~~~~~~~
/usr/include/c++/14/bits/basic_string.h:788:9: note: candidate: 'template<class _Tp, class> std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string(const _Tp&, size_type, size_type, const _Alloc&) [with <template-parameter-2-2> = _Tp; _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]'
788 | basic_string(const _Tp& __t, size_type __pos, size_type __n,
| ^~~~~~~~~~~~
/usr/include/c++/14/bits/basic_string.h:788:9: note: candidate expects 3 arguments, 1 provided
/usr/include/c++/14/bits/basic_string.h:765:9: note: candidate: 'template<class _InputIterator, class> std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string(_InputIterator, _InputIterator, const _Alloc&) [with <template-parameter-2-2> = _InputIterator; _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]'
765 | basic_string(_InputIterator __beg, _InputIterator __end,
| ^~~~~~~~~~~~
/usr/include/c++/14/bits/basic_string.h:765:9: note: candidate expects 2 arguments, 1 provided
/usr/include/c++/14/bits/basic_string.h:669:7: note: candidate: 'template<class> std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string(size_type, _CharT, const _Alloc&) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]'
669 | basic_string(size_type __n, _CharT __c, const _Alloc& __a = _Alloc())
| ^~~~~~~~~~~~
/usr/include/c++/14/bits/basic_string.h:669:7: note: candidate expects 2 arguments, 1 provided
/usr/include/c++/14/bits/basic_string.h:646:7: note: candidate: 'template<class> std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string(const _CharT*, const _Alloc&) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]'
646 | basic_string(const _CharT* __s, const _Alloc& __a = _Alloc())
| ^~~~~~~~~~~~
/usr/include/c++/14/bits/basic_string.h:646:7: note: template argument deduction/substitution failed:
a.cc:40:25: note: cannot convert '(n + 1)' (type 'int_least32_t' {aka 'int'}) to type 'const char*'
40 | string result(n + 1);
| ~~^~~
/usr/include/c++/14/bits/basic_string.h:721:7: note: candidate: 'std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string(std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&&, const _Alloc&) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]'
721 | basic_string(basic_string&& __str, const _Alloc& __a)
| ^~~~~~~~~~~~
/usr/include/c++/14/bits/basic_string.h:721:7: note: candidate expects 2 arguments, 1 provided
/usr/include/c++/14/bits/basic_string.h:716:7: note: candidate: 'std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string(const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&, const _Alloc&) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]'
716 | basic_string(const basic_string& __str, const _Alloc& __a)
| ^~~~~~~~~~~~
/usr/include/c++/14/bits/basic_string.h:716:7: note: candidate expects 2 arguments, 1 provided
/usr/include/c++/14/bits/basic_string.h:711:7: note: candidate: 'std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string(std::initializer_list<_Tp>, const _Alloc&) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]'
711 | basic_string(initializer_list<_CharT> __l, const _Alloc& __a = _Alloc())
| ^~~~~~~~~~~~
/usr/include/c++/14/bits/basic_string.h:711:45: note: no known conversion for argument 1 from 'int_least32_t' {aka 'int'} to 'std::initializer_list<char>'
711 | basic_string(initializer_list<_CharT> __l, const _Alloc& __a = _Alloc())
| ~~~~~~~~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/basic_string.h:682:7: note: candidate: 'std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string(std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&&) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]'
682 | basic_string(basic_string&& __str) noexcept
| ^~~~~~~~~~~~
/usr/include/c++/14/bits/basic_string.h:682:35: note: no known conversion for argument 1 from 'int_least32_t' {aka 'int'} to 'std::__cxx11::basic_string<char>&&'
682 | basic_string(basic_string&& __str) noexcept
| ~~~~~~~~~~~~~~~^~~~~
/usr/include/c++/14/bits/basic_string.h:624:7: note: candidate: 'std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string(const _CharT*, size_type, const _Alloc&) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>; size_type = long unsigned int]'
624 | basic_string(const _CharT* __s, size_type __n,
| ^~~~~~~~~~~~
/usr/include/c++/14/bits/basic_string.h:624:7: note: candidate expects 3 arguments, 1 provided
/usr/include/c++/14/bits/basic_string.h:604:7: note: candidate: 'std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string(const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&, size_type, size_type, const _Alloc&) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>; size_type = long unsigned int]'
604 | basic_string(const basic_string& __str, size_type __pos,
| ^~~~~~~~~~~~
/usr/include/c++/14/bits/basic_string.h:604:7: note: candidate expects 4 arguments, 1 provided
/usr/include/c++/14/bits/basic_string.h:586:7: note: candidate: 'std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string(const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&, size_type, size_type) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>; size_type = long unsigned int]'
586 | basic_string(const basic_string& __str, size_type __pos,
| ^~~~~~~~~~~~
/usr/include/c++/14/bits/basic_string.h:586:7: note: candidate expects 3 arguments, 1 provided
/usr/include/c++/14/bits/basic_string.h:569:7: note: candidate: 'std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string(const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&, size_type, const _Alloc&) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>; size_type = long unsigned int]'
569 | basic_string(const basic_string& __str, size_type __pos,
| ^~~~~~~~~~~~
/usr/include/c++/14/bits/basic_string.h:569:7: note: candidate expects 3 arguments, 1 provided
/usr/include/c++/14/bits/basic_string.h:552:7: note: candidate: 'std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string(const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]'
552 | basic_string(const basic_string& __str)
| ^~~~~~~~~~~~
/usr/include/c++/14/bits/basic_string.h:552:40: note: no known conversion for argument 1 from 'int_least32_t' {aka 'int'} to 'const std::__cxx11::basic_string<char>&'
552 | basic_string(const basic_string& __str)
| ~~~~~~~~~~~~~~~~~~~~^~~~~
/usr/include/c++/14/bits/basic_string.h:540:7: note: candidate: 'std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string(const _Alloc&) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]'
540 | basic_string(const _Alloc& __a) _GLIBCXX_NOEXCEPT
| ^~~~~~~~~~~~
/usr/include/c++/14/bits/basic_string.h:540:34: note: no known conversion for argument 1 from 'int_least32_t' {aka 'in |
s490292017 | p03800 | C++ | #include <iostream>
#include <string>
#include <cstdint>
using namespace std;
char next(char before, char now, char ans)
{
auto inv = [](char animalType){ return animalType == 'S' ? 'W' : 'S'; };
char result{ before };
if(ans != 'o') {
result = inv(result);
}
if(now != 'S') {
result = inv(result);
}
return result;
}
bool judge(string& str, string ans)
{
for(auto i = 1; i < str.size() - 1; ++i) {
str[i + 1] = next(str[i - 1], str[i], ans[i]);
}
return str[0] == str[n];
}
int main()
{
int_least32_t n;
cin >> n;
string input;
cin >> input;
string result(n + 1, 'S');
if(judge(result, input)) {
cout << result << endl;
}
else {
cout << -1 << endl;
}
}
| a.cc: In function 'bool judge(std::string&, std::string)':
a.cc:29:30: error: 'n' was not declared in this scope
29 | return str[0] == str[n];
| ^
|
s473972503 | p03800 | C++ | #include <iostream>
#include <string>
#include <cstdint>
using namespace std;
char next(char before, char now, char ans)
{
auto inv = [](char animalType){ return animalType == 'S' ? 'W' : 'S'; };
char result{ before };
if(ans != 'o') {
result = inv(result);
}
if(now != 'S') {
result = inv(result);
}
return result;
}
bool judge(string& str, string ans)
{
for(auto i = 1; i < str.size() - 1; ++i) {
str[i + 1] = next(str[i - 1], str[i], ans[i]);
}
return str[0] == str[n];
}
int main()
{
int_least32_t n;
cin >> n;
string input;
cin >> input;
string result(n + 1, 'S');
if(judge(result, input) {
cout << result << endl;
}
else {
cout << -1 << endl;
}
}
| a.cc: In function 'bool judge(std::string&, std::string)':
a.cc:29:30: error: 'n' was not declared in this scope
29 | return str[0] == str[n];
| ^
a.cc: In function 'int main()':
a.cc:41:32: error: expected ')' before '{' token
41 | if(judge(result, input) {
| ~ ^~
| )
a.cc:47:1: error: expected primary-expression before '}' token
47 | }
| ^
|
s208920546 | p03800 | C++ | #include <iostream>
#include <string>
#include <cstdint>
using namespace std;
char next(char before, char now, char ans)
{
auto inv = [](char animalType){ return animalType == 'S' ? 'W' : 'S'; };
char result{ before };
if(ans != 'o') {
result = inv(result);
}
if(now != 'S') {
result = inv(result);
}
return result;
}
bool judge(string& str, string ans)
{
for(auto i = 1; i < n; ++i) {
str[i + 1] = next(str[i - 1], str[i], ans[i]);
}
return str[0] == str[n];
}
int main()
{
int_least32_t n;
cin >> n;
string input;
cin >> input;
string result(n + 1, 'S');
if(judge(result, input) {
cout << result << endl;
}
else {
cout << -1 << endl;
}
}
| a.cc: In function 'bool judge(std::string&, std::string)':
a.cc:25:29: error: 'n' was not declared in this scope
25 | for(auto i = 1; i < n; ++i) {
| ^
a.cc:29:30: error: 'n' was not declared in this scope
29 | return str[0] == str[n];
| ^
a.cc: In function 'int main()':
a.cc:41:32: error: expected ')' before '{' token
41 | if(judge(result, input) {
| ~ ^~
| )
a.cc:47:1: error: expected primary-expression before '}' token
47 | }
| ^
|
s794303651 | p03800 | C++ | #include<bits/stdc++.h>
using namespace std;
#define FOR(i,s,e) for (int i=s;i<e;i++)
#define FOE(i,s,e) for (int i=s;i<=e;i++)
#define FOD(i,s,e) for (int i=s;i>=e;i--)
#define SET(a,e) memset(a,e,sizeof(a))
#define LL long long
#define LD long double
#define pb push_back
#define x first
#define y second
#define PII pair<int,int>
#define PLI pair<LL,int>
#define PIL pair<int,LL>
#define PLL pair<LL,LL>
#define PDD pair<LD,LD>
#define eps 1e-9
#define HH1 402653189
#define HH2 1610612741
int n;
char s[100055];
bool ans[100055];
// 0 S truth
// 1 W lie
void solve(bool a, bool b) {
ans[0] = a;
ans[1] = b;
FOR(i, 1, n) {
if (ans[i] == 0) {
if (s[i] == 'o') ans[i + 1] = ans[i - 1];
if (s[i] == 'x') ans[i + 1] = 1 - ans[i - 1];
}
if (ans[i] == 1) {
if (s[i] == 'x') ans[i + 1] = ans[i - 1];
if (s[i] == 'o') ans[i + 1] = 1 - ans[i - 1];
}
}
if (ans[n] != ans[0]) return;
if (ans[0] == 0) {
if (s[i] == 'o' && ans[n - 1] != ans[1]) return;
if (s[i] == 'x' && ans[n - 1] == ans[1]) return;
}
if (ans[0] == 1) {
if (s[i] == 'x' && ans[n - 1] != ans[1]) return;
if (s[i] == 'o' && ans[n - 1] == ans[1]) return;
}
FOR(i, 0, n) printf("%c", ans[i] ? 'W' : 'S');
printf("\n");
exit(0);
}
int main () {
scanf("%d%s", &n, s);
solve(0, 0);
solve(0, 1);
solve(1, 0);
solve(1, 1);
printf("-1\n");
return 0;
} | a.cc: In function 'void solve(bool, bool)':
a.cc:46:23: error: 'i' was not declared in this scope
46 | if (s[i] == 'o' && ans[n - 1] != ans[1]) return;
| ^
a.cc:47:23: error: 'i' was not declared in this scope
47 | if (s[i] == 'x' && ans[n - 1] == ans[1]) return;
| ^
a.cc:51:23: error: 'i' was not declared in this scope
51 | if (s[i] == 'x' && ans[n - 1] != ans[1]) return;
| ^
a.cc:52:23: error: 'i' was not declared in this scope
52 | if (s[i] == 'o' && ans[n - 1] == ans[1]) return;
| ^
|
s501523645 | p03801 | C++ | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MOD2 = 998244353;
vector<P> vp;
int ans[100010];
int main(){
int n;
cin >> n;
rep(i, n) {
ll a;
cin >> a;
vp.push_back({a, i});
}
vp.push_back(0, 0);
sort(vp.rbegin(), vp.rend()); // aが大きいもの、同立ならiが大きいものから取っていく
ll idx = n + 1;
rep(i, n){
idx = min(idx, vp[i].second);
ans[idx] += (i + 1) * (vp[i].first - vp[i+1].first);
}
rep(i, n) cout << ans[i] << endl;
return 0;
}
| a.cc: In function 'int main()':
a.cc:24:17: error: no matching function for call to 'std::vector<std::pair<long long int, long long int> >::push_back(int, int)'
24 | vp.push_back(0, 0);
| ~~~~~~~~~~~~^~~~~~
In file included from /usr/include/c++/14/vector:66,
from /usr/include/c++/14/functional:64,
from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:53,
from a.cc:1:
/usr/include/c++/14/bits/stl_vector.h:1283:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = std::pair<long long int, long long int>; _Alloc = std::allocator<std::pair<long long int, long long int> >; value_type = std::pair<long long int, long long int>]'
1283 | push_back(const value_type& __x)
| ^~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1283:7: note: candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_vector.h:1300:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(value_type&&) [with _Tp = std::pair<long long int, long long int>; _Alloc = std::allocator<std::pair<long long int, long long int> >; value_type = std::pair<long long int, long long int>]'
1300 | push_back(value_type&& __x)
| ^~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1300:7: note: candidate expects 1 argument, 2 provided
|
s544356477 | p03801 | C++ | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MOD2 = 998244353;
vector<P> vp;
int ans[100010];
int main(){
int n;
cin >> n;
rep(i, n) {
ll a;
cin >> a;
vp.push_back({a, i});
}
sort(vp.begin(), vp.end()); // aが大きいもの、同立ならiが大きいものから取っていく
int idx = n + 1;
rep(i, n){
idx = min(idx, vp[i].second);
ans[idx] += (i + 1) * (vp[i].first - vp[i+1].first);
}
rep(i, n) cout << ans[i] << endl;
return 0;
}
| a.cc: In function 'int main()':
a.cc:28:18: error: no matching function for call to 'min(int&, long long int&)'
28 | idx = min(idx, vp[i].second);
| ~~~^~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
233 | min(const _Tp& __a, const _Tp& __b)
| ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: template argument deduction/substitution failed:
a.cc:28:18: note: deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
28 | idx = min(idx, vp[i].second);
| ~~~^~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
281 | min(const _Tp& __a, const _Tp& __b, _Compare __comp)
| ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
5686 | min(initializer_list<_Tp> __l)
| ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
5696 | min(initializer_list<_Tp> __l, _Compare __comp)
| ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: template argument deduction/substitution failed:
a.cc:28:18: note: mismatched types 'std::initializer_list<_Tp>' and 'int'
28 | idx = min(idx, vp[i].second);
| ~~~^~~~~~~~~~~~~~~~~~~
|
s387609375 | p03801 | C++ | #include<bits/stdc++.h>
//#include<atcoder/all>
using namespace std;
//using namespace atcoder;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define all(x) (x).begin(),(x).end()
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
using Graph = vector<vector<ll>>;
// dijkstra
struct edge{ll to, cost;};
typedef pair<ll,ll> P;
struct graph{
ll V;
vector<vector<edge> > G;
vector<ll> d;
graph(ll n){
init(n);
}
void init(ll n){
V = n;
G.resize(V);
d.resize(V);
rep(i,V){
d[i] = INF;
}
}
void add_edge(ll s, ll t, ll cost){
edge e;
e.to = t, e.cost = cost;
G[s].push_back(e);
}
void dijkstra(ll s){
rep(i,V){
d[i] = INF;
}
d[s] = 0;
priority_queue<P,vector<P>, greater<P> > que;
que.push(P(0,s));
while(!que.empty()){
P p = que.top(); que.pop();
ll v = p.second;
if(d[v]<p.first) continue;
for(auto e : G[v]){
if(d[e.to]>d[v]+e.cost){
d[e.to] = d[v]+e.cost;
que.push(P(d[e.to],e.to));
}
}
}
}
};
// dijkstra end
class UnionFind
{
public:
ll par[100005];
ll depth[100005];
ll nGroup[100005];
UnionFind(ll n) {
init(n);
}
void init(ll n) {
for(ll i=0; i<n; i++) {
par[i] = i;
depth[i] = 0;
nGroup[i] = 1;
}
}
ll root(ll x) {
if(par[x] == x) {
return x;
} else {
return par[x] = root(par[x]);
}
}
bool same(ll x, ll y) {
return root(x) == root(y);
}
void unite(ll x, ll y) {
x = root(x);
y = root(y);
if(x == y) return;
if(depth[x] < depth[y]) {
par[x] = y;
nGroup[y] += nGroup[x];
nGroup[x] = 0;
} else {
par[y] = x;
nGroup[x] += nGroup[y];
nGroup[y] = 0;
if(depth[x] == depth[y])
depth[x]++;
}
}
};
// unionfind end
// nCr
const ll MAX = 500010;
ll fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (ll i = 2; i < MAX; i++){
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
// nCr end
// tree DP
vector<ll> depth;
vector<ll> g(10010,0);
ll c[10010];
void dfs(const Graph &G, ll v, ll p, ll &d) {
g[v] = c[d-1];
for (auto nv : G[v]) {
if (nv == p) continue;
d--;
dfs(G, nv, v, d);
}
}
// tree DP end
int main() {
ll n; cin>>n;
ll a[n]={};
rep(i,n) cin>>a[i];
map<ll,ll,greater<ll>> S;
map<ll,ll> pos;
reverse(a,a+n);
rep(i,n){
S[a[i]]++;
pos[a[i]]=n-i;
}
reverse(a,a+n);
ll ans[n]={};
S[0]=0;
for(auto p : S){
ll k = p.fi;
ll k1 = p.se;
auto p1 = p + 1;
ans[pos[k]] = (k-p1.fi)*k1;
if(pos[k]<pos[p1.fi]){
pos[p1.fi]=pos[k];}
S[p1.fi]++;
}
rep(i,n) cout << ans[i] << endl;
}
| a.cc: In function 'int main()':
a.cc:173:17: error: no match for 'operator+' (operand types are 'std::pair<const long long int, long long int>' and 'int')
173 | auto p1 = p + 1;
| ~ ^ ~
| | |
| | int
| std::pair<const long long int, long long int>
In file included from /usr/include/c++/14/bits/stl_algobase.h:67,
from /usr/include/c++/14/algorithm:60,
from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
from a.cc:1:
/usr/include/c++/14/bits/stl_iterator.h:627:5: note: candidate: 'template<class _Iterator> constexpr std::reverse_iterator<_Iterator> std::operator+(typename reverse_iterator<_Iterator>::difference_type, const reverse_iterator<_Iterator>&)'
627 | operator+(typename reverse_iterator<_Iterator>::difference_type __n,
| ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:627:5: note: template argument deduction/substitution failed:
a.cc:173:19: note: mismatched types 'const std::reverse_iterator<_Iterator>' and 'int'
173 | auto p1 = p + 1;
| ^
/usr/include/c++/14/bits/stl_iterator.h:1798:5: note: candidate: 'template<class _Iterator> constexpr std::move_iterator<_IteratorL> std::operator+(typename move_iterator<_IteratorL>::difference_type, const move_iterator<_IteratorL>&)'
1798 | operator+(typename move_iterator<_Iterator>::difference_type __n,
| ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:1798:5: note: template argument deduction/substitution failed:
a.cc:173:19: note: mismatched types 'const std::move_iterator<_IteratorL>' and 'int'
173 | auto p1 = p + 1;
| ^
In file included from /usr/include/c++/14/string:54,
from /usr/include/c++/14/bitset:52,
from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52:
/usr/include/c++/14/bits/basic_string.h:3598:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(const __cxx11::basic_string<_CharT, _Traits, _Allocator>&, const __cxx11::basic_string<_CharT, _Traits, _Allocator>&)'
3598 | operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
| ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3598:5: note: template argument deduction/substitution failed:
a.cc:173:19: note: 'std::pair<const long long int, long long int>' is not derived from 'const std::__cxx11::basic_string<_CharT, _Traits, _Allocator>'
173 | auto p1 = p + 1;
| ^
/usr/include/c++/14/bits/basic_string.h:3616:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(const _CharT*, const __cxx11::basic_string<_CharT, _Traits, _Allocator>&)'
3616 | operator+(const _CharT* __lhs,
| ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3616:5: note: template argument deduction/substitution failed:
a.cc:173:19: note: mismatched types 'const _CharT*' and 'std::pair<const long long int, long long int>'
173 | auto p1 = p + 1;
| ^
/usr/include/c++/14/bits/basic_string.h:3635:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(_CharT, const __cxx11::basic_string<_CharT, _Traits, _Allocator>&)'
3635 | operator+(_CharT __lhs, const basic_string<_CharT,_Traits,_Alloc>& __rhs)
| ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3635:5: note: template argument deduction/substitution failed:
a.cc:173:19: note: mismatched types 'const std::__cxx11::basic_string<_CharT, _Traits, _Allocator>' and 'int'
173 | auto p1 = p + 1;
| ^
/usr/include/c++/14/bits/basic_string.h:3652:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(const __cxx11::basic_string<_CharT, _Traits, _Allocator>&, const _CharT*)'
3652 | operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
| ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3652:5: note: template argument deduction/substitution failed:
a.cc:173:19: note: 'std::pair<const long long int, long long int>' is not derived from 'const std::__cxx11::basic_string<_CharT, _Traits, _Allocator>'
173 | auto p1 = p + 1;
| ^
/usr/include/c++/14/bits/basic_string.h:3670:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(const __cxx11::basic_string<_CharT, _Traits, _Allocator>&, _CharT)'
3670 | operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs, _CharT __rhs)
| ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3670:5: note: template argument deduction/substitution failed:
a.cc:173:19: note: 'std::pair<const long long int, long long int>' is not derived from 'const std::__cxx11::basic_string<_CharT, _Traits, _Allocator>'
173 | auto p1 = p + 1;
| ^
/usr/include/c++/14/bits/basic_string.h:3682:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(__cxx11::basic_string<_CharT, _Traits, _Allocator>&&, const __cxx11::basic_string<_CharT, _Traits, _Allocator>&)'
3682 | operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs,
| ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3682:5: note: template argument deduction/substitution failed:
a.cc:173:19: note: 'std::pair<const long long int, long long int>' is not derived from 'std::__cxx11::basic_string<_CharT, _Traits, _Allocator>'
173 | auto p1 = p + 1;
| ^
/usr/include/c++/14/bits/basic_string.h:3689:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(const __cxx11::basic_string<_CharT, _Traits, _Allocator>&, __cxx11::basic_string<_CharT, _Traits, _Allocator>&&)'
3689 | operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
| ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3689:5: note: template argument deduction/substitution failed:
a.cc:173:19: note: 'std::pair<const long long int, long long int>' is not derived from 'const std::__cxx11::basic_string<_CharT, _Traits, _Allocator>'
173 | auto p1 = p + 1;
| ^
/usr/include/c++/14/bits/basic_string.h:3696:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(__cxx11::basic_string<_CharT, _Traits, _Allocator>&&, __cxx11::basic_string<_CharT, _Traits, _Allocator>&&)'
3696 | operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs,
| ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3696:5: note: template argument deduction/substitution failed:
a.cc:173:19: note: 'std::pair<const long long int, long long int>' is not derived from 'std::__cxx11::basic_string<_CharT, _Traits, _Allocator>'
173 | auto p1 = p + 1;
| ^
/usr/include/c++/14/bits/basic_string.h:3719:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(const _CharT*, __cxx11::basic_string<_CharT, _Traits, _Allocator>&&)'
3719 | operator+(const _CharT* __lhs,
| ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3719:5: note: template argument deduction/substitution failed:
a.cc:173:19: note: mismatched types 'const _CharT*' and 'std::pair<const long long int, long long int>'
173 | auto p1 = p + 1;
| ^
/usr/include/c++/14/bits/basic_string.h:3726:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(_CharT, __cxx11::basic_string<_CharT, _Traits, _Allocator>&&)'
3726 | operator+(_CharT __lhs,
| ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3726:5: note: template argument deduction/substitution failed:
a.cc:173:19: note: mismatched types 'std::__cxx11::basic_string<_CharT, _Traits, _Allocator>' and 'int'
173 | auto p1 = p + 1;
| ^
/usr/include/c++/14/bits/basic_string.h:3733:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(__cxx11::basic_string<_CharT, _Traits, _Allocator>&&, const _CharT*)'
3733 | operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs,
| ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3733:5: note: template argument deduction/substitution failed:
a.cc:173:19: note: 'std::pair<const long long int, long long int>' is not derived from 'std::__cxx11::basic_string<_CharT, _Traits, _Allocator>'
173 | auto p1 = p + 1;
| ^
/usr/include/c++/14/bits/basic_string.h:3740:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(__cxx11::basic_string<_CharT, _Traits, _Allocator>&&, _CharT)'
3740 | operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs,
| ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3740:5: note: template argument deduction/substitution failed:
a.cc:173:19: note: 'std::pair<const long long int, long long int>' is not derived from 'std::__cxx11::basic_string<_CharT, _Traits, _Allocator>'
173 | auto p1 = p + 1;
| ^
In file included from /usr/include/c++/14/ccomplex:39,
from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:127:
/usr/include/c++/14/complex:340:5: note: candidate: 'template<class _Tp> std::complex<_Tp> std::operator+(const complex<_Tp>&, const complex<_Tp>&)'
340 | operator+(const complex<_Tp>& __x, const complex<_Tp>& __y)
| ^~~~~~~~
/usr/include/c++/14/complex:340:5: note: |
s230490884 | p03801 | C++ | //=======================//
// coder: Andy - Tohrumi //
//=======================//
#include <bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(); cin.tie(0); cout.tie(0);
#define rep(i, a, b) for(__typeof(b) i = a; i < b; i++)
#define Rep(i, a, b) for(__typeof(a) i = a; i > b; i--)
#define mp make_pair
typedef pair<int, int> ii;
priority_queue<ii> pq;
signed main() {
fastio;
int n; cin >> n;
int a[n], counter[n];
ll ans[n];
rep(i, 0, n) {
ans[i] = 0;
cin >> a[i];
counter[i] = 1;
pq.push(mp(a[i], i));
}
while(pq.size() > 1) {
ii t1, t2;
t1 = pq.top(); pq.pop();
t2 = pq.top(); pq.pop();
ans[t1.second] += (ll)counter[t1.second] * (t1.first - t2.first);
pq.push(mp(t2.first, min(t1.second, t2.second)));
counter[min(t1.second, t2.second)] += counter[max(t1.second, t2.second)];
}
ans[0] += n * pq.top().first;
rep(i, 0, n) {
cout << ans[i] << "\n";
}
return 0;
}
| a.cc: In function 'int main()':
a.cc:22:9: error: 'll' was not declared in this scope
22 | ll ans[n];
| ^~
a.cc:24:17: error: 'ans' was not declared in this scope; did you mean 'abs'?
24 | ans[i] = 0;
| ^~~
| abs
a.cc:33:17: error: 'ans' was not declared in this scope; did you mean 'abs'?
33 | ans[t1.second] += (ll)counter[t1.second] * (t1.first - t2.first);
| ^~~
| abs
a.cc:37:9: error: 'ans' was not declared in this scope; did you mean 'abs'?
37 | ans[0] += n * pq.top().first;
| ^~~
| abs
|
s034672851 | p03801 | C++ | #include<bits/stdc++.h>
using ll = long long;
using namespace std;
const ll INF = 10000000000000000;
const ll mod = 1000000007;
ll test[1234567811], kosuu[1234567811], saishou[1234567811];
ll ans[12345678];
signed main() {
ll n, m; cin >> n;
vector<ll> v, kari;
for (int h = 1; h <= n; h++) {
cin >> test[h];
kosuu[test[h]]++; kari.push_back(test[h]);
if (saishou[test[h]] == 0) {
saishou[test[h]] = h;
}
}
sort(kari.begin(), kari.end());
for (int h = 0; h < kari.size(); h++) {
if (h == 0) { v.push_back(kari[h]); continue; }
if (kari[h - 1] != kari[h]) { v.push_back(kari[h]); }
}
for (int h = v.size() - 1; h > 0; h--) {
ans[saishou[v[h]]] = kosuu[v[h]] * (v[h] - v[h - 1]);
kosuu[v[h - 1]] += kosuu[v[h]];
}
for (int h = 1; h <= n; h++) {
if (h == 1) { cout << kosuu[v[h - 1]] << endl; continue; }
cout << ans[h] << endl;
}
cin >> n; return 0;
} | /tmp/cc5gjusb.o: in function `main':
a.cc:(.text+0x91): relocation truncated to fit: R_X86_64_PC32 against symbol `kosuu' defined in .bss section in /tmp/cc5gjusb.o
a.cc:(.text+0xa8): relocation truncated to fit: R_X86_64_PC32 against symbol `kosuu' defined in .bss section in /tmp/cc5gjusb.o
a.cc:(.text+0xf9): relocation truncated to fit: R_X86_64_PC32 against symbol `saishou' defined in .bss section in /tmp/cc5gjusb.o
a.cc:(.text+0x12e): relocation truncated to fit: R_X86_64_PC32 against symbol `saishou' defined in .bss section in /tmp/cc5gjusb.o
a.cc:(.text+0x270): relocation truncated to fit: R_X86_64_PC32 against symbol `kosuu' defined in .bss section in /tmp/cc5gjusb.o
a.cc:(.text+0x2d8): relocation truncated to fit: R_X86_64_PC32 against symbol `saishou' defined in .bss section in /tmp/cc5gjusb.o
a.cc:(.text+0x2eb): relocation truncated to fit: R_X86_64_PC32 against symbol `ans' defined in .bss section in /tmp/cc5gjusb.o
a.cc:(.text+0x316): relocation truncated to fit: R_X86_64_PC32 against symbol `kosuu' defined in .bss section in /tmp/cc5gjusb.o
a.cc:(.text+0x344): relocation truncated to fit: R_X86_64_PC32 against symbol `kosuu' defined in .bss section in /tmp/cc5gjusb.o
a.cc:(.text+0x35b): relocation truncated to fit: R_X86_64_PC32 against symbol `kosuu' defined in .bss section in /tmp/cc5gjusb.o
a.cc:(.text+0x3a9): additional relocation overflows omitted from the output
collect2: error: ld returned 1 exit status
|
s208233790 | p03801 | C++ | Frequency | a.cc:1:1: error: 'Frequency' does not name a type
1 | Frequency
| ^~~~~~~~~
|
s362969942 | p03801 | C++ | #include <algorithm>
#include <cmath>
#include <complex>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#include <functional>
#include <cstring>
#include <regex>
#include <random>
#include <cassert>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, s, n) for (int i = (s); i < (int)(n); i++)
#define revrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define revrepr(i, s, n) for (int i = (n) - 1; i >= s; i--)
#define debug(x) cerr << #x << ": " << x << "\n"
using ll = long long;
using P = pair<int, int>;
const long long MOD = 1e9+7;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T>
istream& operator >>(istream &is, vector<T> &v) {
for (int i = 0; i < (int)v.size(); i++) cin >> v.at(i);
return is;
}
template<class T, class U>
ostream& operator <<(ostream &os, pair<T, U> p) {
cout << '(' << p.first << ", " << p.second << ')';
return os;
}
template<class T>
void print(const vector<T> &v, const string &delimiter) { rep(i, v.size()) cout << (0 < i ? delimiter : "") << v.at(i); cout << endl; }
template<class T>
void print(const vector<vector<T>> &vv, const string &delimiter) { for (const auto &v: vv) print(v, delimiter); }
int main() {
int n;
cin >> n;
vector<ll> a(n);
cin >> a;
int max_a = 0;
vector<int> idxs;
rep(i, n) if (chmax(max_a, a[i])) idxs.push_back(i);
vector<ll> b(n);
rep(i, n) b[i] = a[i];
sort(b.rbegin(), b.rend());
vector<ll> sum(n + 1);
rep(i, n) sum[i + 1] = sum[i] + b[i];
auto search = [&](int x){
int ng = n;
int ok = -1;
while (abs(ok - ng) > 1) {
int mid = (ok + ng) / 2;
if (b[mid] > x) ok = mid;
else ng = mid;
}
return ok;
};
vector<ll> ans_sum(idxs.size() + 1);
ans_sum[0] = sum[n];
rep(i, idxs.size()) {
int u = search(a[idxs[i]]);
//cout << u << endl;
ans_sum[i + 1] = sum[u + 1] - a[idxs[i]] * (u + 1);
}
vector<ll> ans(n + 1);
rep(i, idxs.size()) {
ans[idxs[i]] = ans_sum[i] - ans_sum[i + 1];
}
rep(i, n) cout << ans[i] << endl;
} | a.cc: In function 'int main()':
a.cc:56:24: error: no matching function for call to 'chmax(int&, __gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type&)'
56 | rep(i, n) if (chmax(max_a, a[i])) idxs.push_back(i);
| ~~~~~^~~~~~~~~~~~~
a.cc:27:31: note: candidate: 'template<class T> bool chmax(T&, T)'
27 | template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
| ^~~~~
a.cc:27:31: note: template argument deduction/substitution failed:
a.cc:56:24: note: deduced conflicting types for parameter 'T' ('int' and 'long long int')
56 | rep(i, n) if (chmax(max_a, a[i])) idxs.push_back(i);
| ~~~~~^~~~~~~~~~~~~
|
s612340918 | p03801 | C++ | #include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)n; i++)
using ll = long long;
template <typename T>
class SegTree{
using F = function<T(T,T)>;
int n; T uni; F f;
vector<T> dat;
T query_sub(int a, int b, int k, int l, int r) {
if(r <= a || b <= l) return uni;
if(a <= l && r <= b) return dat[k];
T vl = query_sub(a, b, k*2+1, l, (l+r)/2);
T vr = query_sub(a, b, k*2+2, (l+r)/2, r);
return f(vl,vr);
}
public:
SegTree(int _n, F f, T uni) : f(f), uni(uni) {
n = 1;
while(n < _n) n *= 2;
dat = vector<T>(2*n-1,uni);
}
void update(int k, T a) {
k += n-1;
dat[k] += a;
while(k > 0){
k = (k-1)/2;
dat[k] = f(dat[2*k+1], dat[2*k+2]);
}
}
T query(int a, int b) {
return query_sub(a, b, 0, 0, n);
} // [a,b)
};
int main(){
int n;
cin >> n;
ll a[n];
SegTree<ll> st(n,[](ll a,ll b){return max(a,b);},(ll)0);
set<ll> s;
rep(i,n) {
cin >> a[i];
s.insert(a[i]);
st.update(i,a[i]);
}
map<ll,ll> m;
for(auto k : s) m[k] = p++;
cout << p << endl;
SegTree<ll> sum(p,[](ll a, ll b){return a + b;},(ll)0);
rep(i,n) sum.update(m[a[i]],1);
vector<ll> ans(n,0);
rep(i,n) ans[0] += min(a[0],a[i]);
sum.update(m[a[0]],-1);
for(int i = 1; i < n; i++) {
ll d = st.query(0,i);
ll c = sum.query(m[a[i]],p);
ans[i] = c*max((ll)0,a[i]-d);
sum.update(m[a[i]],-1);
}
for(auto k : ans) cout << k << endl;
return 0;
} | a.cc: In function 'int main()':
a.cc:49:26: error: 'p' was not declared in this scope
49 | for(auto k : s) m[k] = p++;
| ^
a.cc:50:11: error: 'p' was not declared in this scope
50 | cout << p << endl;
| ^
|
s273685611 | p03801 | C++ | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
int main()
{
ll n ;
cin >> n ;
vector<ll> ans(n);
vector<ll> a(n);
rep(i, n){
cin >> a[i];
}
map<ll,pair<ll,ll>> m;
rep(i,n){
m[a[i]].first++;
if(m[a[i]].first==1)m[a[i]].second=i+1;
}
ll num=0,cnt,itr;
ll minitr;
ll sum=0;
for (auto i = m.rbegin(); i != m.rend(); ++i) {
if(num==0){
num=i->first;
cnt=i->second.first;
itr=i->second.second;
minitr=itr-1;
continue;
}
ans[minitr]+=(cnt+sum)*(num-i->first);
sum+=cnt;
minitr=min(minitr,itr-1);
num=i->first;
cnt=i->second.first;
itr=i->second.second;
}
ans[minitr]+=(cnt+sum)*(num-i->first);
for(auto an:ans)cout << an << endl;
return 0;
} | a.cc: In function 'int main()':
a.cc:38:29: error: 'i' was not declared in this scope
38 | ans[minitr]+=(cnt+sum)*(num-i->first);
| ^
|
s329359990 | p03801 | C++ | #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>
using namespace std;
//#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
#define dump(x) cerr << #x << " = " << (x) << endl;
#else
#define dump(x) ;
#endif
#define EPS (1e-10)
#define equals(a,b) (fabs((a)-(b)) < EPS)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back
//#define int long long
typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
template <typename T>
std::string printVector(const std::vector<T> &data)
{
std::stringstream ss;
std::ostream_iterator<T> out_it(ss, ", ");
ss << "[";
std::copy(data.begin(), data.end() - 1, out_it);
ss << data.back() << "]";
return ss.str();
}
const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;
signed main(int argc, char const *argv[])
{
cin.tie(0);
ios::sync_with_stdio(false);
int N; cin >> N;
VI a(N);
map<int,LL> mpcnt;
map<int,LL> mparg;
LL sum = 0;
REP(i,N){
cin >> a[i];
mpcnt[a[i]]++;
if(mparg[a[i]] != 0){
mparg[a[i]] = min(mparg[a[i]],i+1);
}else{
mparg[a[i]] = i+1;
}
sum += a[i];
}
VL ans(N+1);
for(auto itr = mpcnt.end(); itr != next(mpcnt.begin(),1); itr--){
auto pitr = prev(itr,1);
auto qitr = prev(itr,2);
dump(pitr->first)
dump(pitr->second)
dump(qitr->first)
dump(qitr->second)
ans[mparg[pitr->first]] += pitr->second * (pitr->first - qitr->first);
//cout << "num:" << mparg[pitr->first] << endl;
//cout << "add:" << pitr->second * (pitr->first - qitr->first) << endl;
qitr->second += pitr->second ;
mparg[qitr->first] = min(mparg[qitr->first],mparg[pitr->first]);
//if(itr == next(mpcnt.begin(),2)){
//}
}
FOR(i,1,N+1){
sum -= ans[i];
}
ans[1] += sum;
FOR(i,1,N+1){
cout << ans[i] << endl;
}
}
| a.cc: In function 'int main(int, const char**)':
a.cc:76:30: error: no matching function for call to 'min(std::map<int, long long int>::mapped_type&, int)'
76 | mparg[a[i]] = min(mparg[a[i]],i+1);
| ~~~^~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/string:51,
from /usr/include/c++/14/bits/locale_classes.h:40,
from /usr/include/c++/14/bits/ios_base.h:41,
from /usr/include/c++/14/ios:44,
from /usr/include/c++/14/ostream:40,
from /usr/include/c++/14/iostream:41,
from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
233 | min(const _Tp& __a, const _Tp& __b)
| ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: template argument deduction/substitution failed:
a.cc:76:30: note: deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
76 | mparg[a[i]] = min(mparg[a[i]],i+1);
| ~~~^~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
281 | min(const _Tp& __a, const _Tp& __b, _Compare __comp)
| ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61,
from a.cc:4:
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
5686 | min(initializer_list<_Tp> __l)
| ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
5696 | min(initializer_list<_Tp> __l, _Compare __comp)
| ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: template argument deduction/substitution failed:
a.cc:76:30: note: mismatched types 'std::initializer_list<_Tp>' and 'long long int'
76 | mparg[a[i]] = min(mparg[a[i]],i+1);
| ~~~^~~~~~~~~~~~~~~~~
|
s101937407 | p03801 | C++ | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
int a[n];
pair<ll,ll> p[n];
rep(i,n){
cin >> a[i];
p[i]=mp(a[i],i);
}
sort(p,p+n);
reverse(p,p+n);
ll ans[n];
rep(i,n) ans[i]=0;
int ind=n;
rep(i,n){
ind=min(ind, p[i].second);
if(i==n-1) ans[ind]+=(i+1)*(p[i].first-0);
else ans[ind]+=(i+1)*(p[i].first-p[i+1].first);
// cout << ans[ind] << endl;
}
rep(i,n){
cout << ans[i] << endl;
}
return 0;
}
| a.cc: In function 'int main()':
a.cc:29:12: error: no matching function for call to 'min(int&, long long int&)'
29 | ind=min(ind, p[i].second);
| ~~~^~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
233 | min(const _Tp& __a, const _Tp& __b)
| ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: template argument deduction/substitution failed:
a.cc:29:12: note: deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
29 | ind=min(ind, p[i].second);
| ~~~^~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
281 | min(const _Tp& __a, const _Tp& __b, _Compare __comp)
| ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
5686 | min(initializer_list<_Tp> __l)
| ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
5696 | min(initializer_list<_Tp> __l, _Compare __comp)
| ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: template argument deduction/substitution failed:
a.cc:29:12: note: mismatched types 'std::initializer_list<_Tp>' and 'int'
29 | ind=min(ind, p[i].second);
| ~~~^~~~~~~~~~~~~~~~~~
|
s810551716 | p03801 | C++ | #include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
const double PI = acos(-1);
const double EPS = 1e-15;
long long INF=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
long long c=a%i_7;
if(c>=0)return c;
return c+i_7;
}
using namespace std;
bool prime_(int n){
if(n==1){
return false;
}else if(n==2){
return true;
}else{
for(int i=2;i<=sqrt(n);i++){
if(n%i==0){
return false;
}
}
return true;
}
}
long long gcd_(long long a, long long b){
if(a<b){
swap(a,b);
}
if(a%b==0){
return b;
}else{
return gcd_(b,a%b);
}
}
long long lcm_(long long x, long long y){
return (x/gcd_(x,y))*y;
}
class UnionFind {
public:
//各頂点の親の番号を格納する。その頂点自身が親だった場合は-(その集合のサイズ)を入れる。
vector<int> Parent;
//クラスを作るときは、Parentの値を全て-1にする。
//以下のようにすると全てバラバラの頂点として解釈できる。
UnionFind(int N) {
Parent = vector<int>(N, -1);
}
//Aがどのグループに属しているか調べる
int root(int A) {
if (Parent[A] < 0) return A;
return Parent[A] = root(Parent[A]);
}
//自分のいるグループの頂点数を調べる
int size(int A) {
return -Parent[root(A)];//先祖をrootで取っておきたい。
}
//AとBをくっ付ける
bool connect(int A, int B) {
//AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
A = root(A);
B = root(B);
if (A == B) {
//すでにくっついてるからくっ付けない
return false;
}
//大きい方(A)に小さいほう(B)をくっ付けたい
//大小が逆だったらAとBをひっくり返す。
if (size(A) < size(B)) swap(A, B);
//Aのサイズを更新する
Parent[A] += Parent[B];
//Bの親をAに変更する
Parent[B] = A;
return true;
}
};
int main(){
int n;
cin>>n;
long long a[n];
REP(i,n){
cin>>a[i];
}
vector<int> cand;
long long temp = 0;
REP(i,n){
if(a[i]>temp){
temp = a[i];
cand.push_back(i);
}
}
reverse(ALL(cand));
vector<pair<long long, int>> num_and_index;
long long csum[n]={};
REP(i,n){
num_and_index.push_back(make_pair(a[i],i));
}
sort(ALL(num_and_index), greater<pair<long long, int>>());
REP(i,n){
if(i==0){
csum[i] = num_and_index[i].first;
}else{
csum[i] = csum[i-1] + num_and_index[i].first;
}
}
int s = cand.size();//sは常に1以上
int index = 0;
long long conut = 0;
long long ans[n] = {};
REP(i,s){
if(i==0){
continue;
}
while(num_and_index[index].second != cand[i]){
index++;
}
if(i==1){
ans[cand[i-1]] += csum[index] - ((long long)index+1)*num_and_index[index].first;
}else{
ans[cand[i-1]] += csum[index] - ((long long)index+1)*num_and_index[index].first - ans[cand[i-2]];
}
cnt += ans[cand[i-1]];
}
ans[cand[s-1]] += csum[n-1] - cnt;
REP(i,n){
cout<<ans[i]<<endl;
}
return 0;
}
| a.cc: In function 'int main()':
a.cc:140:5: error: 'cnt' was not declared in this scope; did you mean 'int'?
140 | cnt += ans[cand[i-1]];
| ^~~
| int
a.cc:142:33: error: 'cnt' was not declared in this scope; did you mean 'int'?
142 | ans[cand[s-1]] += csum[n-1] - cnt;
| ^~~
| int
|
s418687696 | p03801 | C++ | #include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
const double PI = acos(-1);
const double EPS = 1e-15;
long long INF=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
long long c=a%i_7;
if(c>=0)return c;
return c+i_7;
}
using namespace std;
bool prime_(int n){
if(n==1){
return false;
}else if(n==2){
return true;
}else{
for(int i=2;i<=sqrt(n);i++){
if(n%i==0){
return false;
}
}
return true;
}
}
long long gcd_(long long a, long long b){
if(a<b){
swap(a,b);
}
if(a%b==0){
return b;
}else{
return gcd_(b,a%b);
}
}
long long lcm_(long long x, long long y){
return (x/gcd_(x,y))*y;
}
class UnionFind {
public:
//各頂点の親の番号を格納する。その頂点自身が親だった場合は-(その集合のサイズ)を入れる。
vector<int> Parent;
//クラスを作るときは、Parentの値を全て-1にする。
//以下のようにすると全てバラバラの頂点として解釈できる。
UnionFind(int N) {
Parent = vector<int>(N, -1);
}
//Aがどのグループに属しているか調べる
int root(int A) {
if (Parent[A] < 0) return A;
return Parent[A] = root(Parent[A]);
}
//自分のいるグループの頂点数を調べる
int size(int A) {
return -Parent[root(A)];//先祖をrootで取っておきたい。
}
//AとBをくっ付ける
bool connect(int A, int B) {
//AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
A = root(A);
B = root(B);
if (A == B) {
//すでにくっついてるからくっ付けない
return false;
}
//大きい方(A)に小さいほう(B)をくっ付けたい
//大小が逆だったらAとBをひっくり返す。
if (size(A) < size(B)) swap(A, B);
//Aのサイズを更新する
Parent[A] += Parent[B];
//Bの親をAに変更する
Parent[B] = A;
return true;
}
};
int main(){
int n;
cin>>n;
long long a[n];
REP(i,n){
cin>>a[i];
}
vector<int> cand;
long long temp = 0;
REP(i,n){
if(a[i]>temp){
temp = a[i];
cand.push_back(i);
}
}
reverse(ALL(cand));
vector<pair<long long, int>> num_and_index;
long long csum[n]={};
REP(i,n){
num_and_index.push_back(make_pair(a[i],i));
}
sort(ALL(num_and_index), greater<pair<long long, int>>());
REP(i,n){
if(i==0){
csum[i] = num_and_index[i].first;
}else{
csum[i] = csum[i-1] + num_and_index[i].first;
}
}
int s = cand.size();//sは常に1以上
int index = 0;
long long conut = 0;
long long ans[n] = {};
REP(i,s){
if(i==0){
continue;
}
while(num_and_index[index].second != cand[i]){
index++;
}
if(i==1){
ans[cand[i-1]] += csum[index] - ((long long)index+1)*num_and_index[index].first;
}else{
ans[cand[i-1]] += csum[index] - ((long long)index+1)*num_and_index[index].first - ans[cand[i-2]];
}
count += ans[cand[i-1]];
}
ans[cand[s-1]] += csum[n-1] - count;
REP(i,n){
cout<<ans[i]<<endl;
}
return 0;
}
| a.cc: In function 'int main()':
a.cc:140:27: error: overloaded function with no contextual type information
140 | count += ans[cand[i-1]];
| ^
a.cc:142:31: error: invalid operands of types 'long long int' and '<unresolved overloaded function type>' to binary 'operator-'
142 | ans[cand[s-1]] += csum[n-1] - count;
| ~~~~~~~~~~^~~~~~~
|
s893708466 | p03801 | C++ | int N;
ll A[101010];
vector<int> V;
ll ret[101010];
void solve() {
int i,j,k,l,r,x,y; string s;
cin>>N;
map<ll,ll> M;
FOR(i,N) cin>>A[i], M[A[i]]++;
V.push_back(0);
for(i=1;i<N;i++) if(A[V.back()]<A[i]) V.push_back(i);
for(i=V.size()-2;i>=0;i--) {
auto r=*M.rbegin();
M.erase(r.first);
ret[V[i+1]] += (r.first-A[V[i]])*1LL*r.second;
M[A[V[i]]]+=r.second;
}
FORR(r,M) ret[0] += r.first*r.second;
FOR(i,N) cout<<ret[i]<<endl;
} | a.cc:2:1: error: 'll' does not name a type
2 | ll A[101010];
| ^~
a.cc:3:1: error: 'vector' does not name a type
3 | vector<int> V;
| ^~~~~~
a.cc:4:1: error: 'll' does not name a type
4 | ll ret[101010];
| ^~
a.cc: In function 'void solve()':
a.cc:8:28: error: 'string' was not declared in this scope
8 | int i,j,k,l,r,x,y; string s;
| ^~~~~~
a.cc:10:9: error: 'cin' was not declared in this scope
10 | cin>>N;
| ^~~
a.cc:11:9: error: 'map' was not declared in this scope
11 | map<ll,ll> M;
| ^~~
a.cc:11:13: error: 'll' was not declared in this scope; did you mean 'l'?
11 | map<ll,ll> M;
| ^~
| l
a.cc:11:20: error: 'M' was not declared in this scope
11 | map<ll,ll> M;
| ^
a.cc:12:9: error: 'FOR' was not declared in this scope
12 | FOR(i,N) cin>>A[i], M[A[i]]++;
| ^~~
a.cc:13:9: error: 'V' was not declared in this scope
13 | V.push_back(0);
| ^
a.cc:14:29: error: 'A' was not declared in this scope
14 | for(i=1;i<N;i++) if(A[V.back()]<A[i]) V.push_back(i);
| ^
a.cc:18:25: error: 'ret' was not declared in this scope
18 | ret[V[i+1]] += (r.first-A[V[i]])*1LL*r.second;
| ^~~
a.cc:18:49: error: 'A' was not declared in this scope
18 | ret[V[i+1]] += (r.first-A[V[i]])*1LL*r.second;
| ^
a.cc:21:9: error: 'FORR' was not declared in this scope
21 | FORR(r,M) ret[0] += r.first*r.second;
| ^~~~
|
s592766338 | p03801 | C++ | int N;
ll A[100010];
ll ans[100010];
{
pair<int, int> last;
int stk, left;
rd(N, A(N));
priority_queue<pair<int, int>> pq;
REP(i, N) pq.emplace(A[i], i);
stk = 0;
left = pq.top().second;
while (!pq.empty()) {
last = pq.top();
int now, next;
now = pq.top().first;
while (!pq.empty() && pq.top().first == last.first) {
++stk;
last.second = pq.top().second;
pq.pop();
}
next = pq.empty() ? 0 : pq.top().first;
left = min(left, last.second);
ans[left] += stk*(now-next);
}
wtLn(ans(N));
} | a.cc:2:1: error: 'll' does not name a type
2 | ll A[100010];
| ^~
a.cc:3:1: error: 'll' does not name a type
3 | ll ans[100010];
| ^~
a.cc:5:1: error: expected unqualified-id before '{' token
5 | {
| ^
|
s646527771 | p03801 | C++ | #include<cstdio>
#include<algorithm>
#define int long long;
using namespace std;
struct arr
{
int aa,bb;
}a[100010];
int n;
long long b[100010];
int cmp(arr x,arr y)
{
if (x.aa!=y.aa) return x.aa>y.aa;
return x.bb<y.bb;
}
signed main()
{
scanf("%lld",&n);
for (int i=1;i<=n;i++)
{
scanf("%lld",&a[i].aa);
a[i].bb=i;b[i]=0;
}
sort(a+1,a+1+n,cmp);
int maxa=1;int maxb=1;
while (true)
{
while ((a[maxb].aa==a[maxa].aa) && (maxb<=n)) maxb=maxb+1;
if (maxb>n) break;
b[a[maxa].bb]+=(maxb-1)*(a[maxa].aa-a[maxb].aa);
a[maxa].aa=a[maxb].aa;
if (a[maxa].bb>a[maxb].bb) maxa=maxb;
}
b[a[maxa].bb]+=a[maxa].aa*n;
for (int i=1;i<=n;i++) printf("%lld\n",b[i]);
return 0;
} | a.cc:3:18: error: declaration does not declare anything [-fpermissive]
3 | #define int long long;
| ^~~~
a.cc:7:4: note: in expansion of macro 'int'
7 | int aa,bb;
| ^~~
a.cc:7:8: error: 'aa' does not name a type
7 | int aa,bb;
| ^~
a.cc:3:18: error: declaration does not declare anything [-fpermissive]
3 | #define int long long;
| ^~~~
a.cc:9:1: note: in expansion of macro 'int'
9 | int n;
| ^~~
a.cc:9:5: error: 'n' does not name a type
9 | int n;
| ^
a.cc:3:18: error: declaration does not declare anything [-fpermissive]
3 | #define int long long;
| ^~~~
a.cc:11:1: note: in expansion of macro 'int'
11 | int cmp(arr x,arr y)
| ^~~
a.cc:11:5: error: ISO C++ forbids declaration of 'cmp' with no type [-fpermissive]
11 | int cmp(arr x,arr y)
| ^~~
a.cc: In function 'int cmp(arr, arr)':
a.cc:13:10: error: 'struct arr' has no member named 'aa'
13 | if (x.aa!=y.aa) return x.aa>y.aa;
| ^~
a.cc:13:16: error: 'struct arr' has no member named 'aa'
13 | if (x.aa!=y.aa) return x.aa>y.aa;
| ^~
a.cc:13:29: error: 'struct arr' has no member named 'aa'
13 | if (x.aa!=y.aa) return x.aa>y.aa;
| ^~
a.cc:13:34: error: 'struct arr' has no member named 'aa'
13 | if (x.aa!=y.aa) return x.aa>y.aa;
| ^~
a.cc:14:13: error: 'struct arr' has no member named 'bb'
14 | return x.bb<y.bb;
| ^~
a.cc:14:18: error: 'struct arr' has no member named 'bb'
14 | return x.bb<y.bb;
| ^~
a.cc: In function 'int main()':
a.cc:18:18: error: 'n' was not declared in this scope
18 | scanf("%lld",&n);
| ^
a.cc:3:18: error: declaration does not declare anything [-fpermissive]
3 | #define int long long;
| ^~~~
a.cc:19:9: note: in expansion of macro 'int'
19 | for (int i=1;i<=n;i++)
| ^~~
a.cc:19:13: error: 'i' was not declared in this scope
19 | for (int i=1;i<=n;i++)
| ^
a.cc:19:21: error: expected ')' before ';' token
19 | for (int i=1;i<=n;i++)
| ~ ^
| )
a.cc:19:22: error: 'i' was not declared in this scope
19 | for (int i=1;i<=n;i++)
| ^
a.cc:3:18: error: declaration does not declare anything [-fpermissive]
3 | #define int long long;
| ^~~~
a.cc:25:4: note: in expansion of macro 'int'
25 | int maxa=1;int maxb=1;
| ^~~
a.cc:25:8: error: 'maxa' was not declared in this scope
25 | int maxa=1;int maxb=1;
| ^~~~
a.cc:3:18: error: declaration does not declare anything [-fpermissive]
3 | #define int long long;
| ^~~~
a.cc:25:15: note: in expansion of macro 'int'
25 | int maxa=1;int maxb=1;
| ^~~
a.cc:25:19: error: 'maxb' was not declared in this scope
25 | int maxa=1;int maxb=1;
| ^~~~
a.cc:3:18: error: declaration does not declare anything [-fpermissive]
3 | #define int long long;
| ^~~~
a.cc:35:9: note: in expansion of macro 'int'
35 | for (int i=1;i<=n;i++) printf("%lld\n",b[i]);
| ^~~
a.cc:35:21: error: expected ')' before ';' token
35 | for (int i=1;i<=n;i++) printf("%lld\n",b[i]);
| ~ ^
| )
|
s844995933 | p03801 | C++ | #pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#define For(i,j,k) for(int i=j;i<=k;++i)
#define Dow(i,j,k) for(int i=k;i>=j;--i)
#define ll long long
#define int ll
#define pb push_back
using namespace std;
inline ll read()
{
ll t=0,dp=1;char c=getchar();
while(!isdigit(c)) {if(c=='-') dp=-1;c=getchar();}
while(isdigit(c)) t=t*10+c-48,c=getchar();
return t*dp;
}
inline void write(ll x){if(x<0) {putchar('-');x=-x;} if(x>=10) write(x/10);putchar(x%10+48);}
inline void writeln(ll x){write(x);puts("");}
inline void write_p(ll x){write(x);putchar(' ');}
/*------------------------------------------------------------------------------------------------------*/
const int N=1e5+5;
int n;
struct node{int v,num;} p[N];
int ans[N];
inline bool cmp(node x,node y){return x.v>y.v;}
int main()
{
n=read();
For(i,1,n) p[i].v=read(),p[i].num=i;
sort(p+1,p+n+1,cmp);
int now=1,to=p[1].num;
For(i,2,n)
{
if(p[i].v==p[i-1].v) now++;
else ans[to]=(p[i-1].v-p[i].v)*now,now++;
to=min(to,p[i].num);
}
ans[to]=(p[n].v-p[n+1].v)*now,now++;
For(i,1,n) writeln(ans[i]);
} | cc1plus: error: '::main' must return 'int'
|
s612887740 | p03801 | C++ | n = int(input())
a = list(map(int, input().split()))
ans = [0]*n
b = []
for i, x in enumerate(a):
b.append([-x, i])
b.sort()
c = []
p = b[0]
x = [-b[0][0], b[0][1], 1]
for i in range(1, n):
if -b[i][0] == x[0]:
x[2] = i+1
else:
c.append(x)
x = [-b[i][0], b[i][1], i+1]
c.append(x)
s = 0
for i in range(len(c)-1):
x = (c[i][0]-c[i+1][0])*c[i][2]
ans[c[i][1]] = x
s += x
ans[c[-1][1]] = sum(a)-s
for x in ans:
print(x)
| a.cc:1:1: error: 'n' does not name a type
1 | n = int(input())
| ^
|
s548038380 | p03801 | C++ | //#define NDEBUG
#define _CRT_SECURE_NO_WARNINGS
#include <array>
#include <cstddef>
#include <cstdint>
#include <cstdio>
#include <limits>
#include <memory>
#include <string>
#include <type_traits>
template <class Integral> class Rirange;
template <class Integral = std::size_t> class irange {
public:
using value_type = Integral;
using reference = value_type &;
using const_reference = const value_type &;
class irangeitr {
friend irange;
value_type i;
irangeitr(const value_type x) noexcept : i(x) {}
public:
void operator++() noexcept { ++i; }
value_type &operator*() noexcept { return i; }
const_reference operator*() const noexcept { return i; }
bool operator!=(const irangeitr &x) const noexcept { return i < x.i; }
};
private:
const value_type f, l;
public:
irange(const value_type first, const value_type last) noexcept
: f(first), l(last) {}
irangeitr begin() const noexcept { return irangeitr(f); }
irangeitr end() const noexcept { return irangeitr(l); }
Rirange<value_type> rev() const noexcept {
return Rirange<value_type>(l - 1, f - 1);
}
};
template <class Integral = std::size_t> class Rirange {
public:
using value_type = Integral;
using reference = value_type &;
using const_reference = const value_type &;
class Rirangeitr {
friend Rirange;
value_type i;
Rirangeitr(const value_type x) noexcept : i(x) {}
public:
void operator++() noexcept { --i; }
reference operator*() noexcept { return i; }
const_reference operator*() const noexcept { return i; }
bool operator!=(const Rirangeitr &x) const noexcept {
return (!~x.i && ~i) || x.i < i;
}
};
private:
const value_type f, l;
public:
Rirange(const value_type x, const value_type y) noexcept : f(x), l(y) {}
Rirangeitr begin() const noexcept { return Rirangeitr(f); }
Rirangeitr end() const noexcept { return Rirangeitr(l); }
irange<value_type> rev() const noexcept {
return irange<value_type>(l + 1, f + 1);
}
};
template <class T> bool maxi(T &a, const T &b) {
if (b < a)
return 0;
a = b;
return 1;
}
template <class T> bool mini(T &a, const T &b) {
if (a < b)
return 0;
a = b;
return 1;
}
template <class T> bool smaxi(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool smini(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
struct customIO {
int c;
bool f;
std::array<int, 30> buf;
const std::array<int, 10> itoc;
std::array<std::uint_least8_t, 256> ctoi_base;
const std::uint_least8_t *const ctoi;
void get_c() { c = fgetc(stdin); }
void put_c(int x) { fputc(x, stdout); }
bool vacant() { return c == ' ' || c == '\n'; }
operator int() { return 0; }
explicit customIO()
: itoc({ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' }),
ctoi(std::addressof(ctoi_base[-static_cast<std::int_fast16_t>(
std::numeric_limits<char>::min())])) {
for (std::uint_least8_t i = 0; i < 10; ++i)
ctoi_base[static_cast<int>("0123456789"[i]) -
static_cast<std::int_fast16_t>(
std::numeric_limits<char>::min())] = i;
}
// in
void cueing() {
while (get_c(), vacant())
;
}
template <class T>
auto operator>>(T &d) ->
typename std::enable_if<std::is_signed<T>::value, customIO &>::type {
d = 0;
f = 0;
cueing();
if (c == '-')
f = 1, get_c();
do
d = d * 10 + ctoi[c];
while (get_c(), !vacant());
if (f)
d = -d;
return *this;
}
template <class T>
auto operator>>(T &d) ->
typename std::enable_if<!std::is_signed<T>::value, customIO &>::type {
d = 0;
cueing();
do
d = d * 10 + ctoi[c];
while (get_c(), !vacant());
return *this;
}
customIO &operator>>(char &d) {
cueing();
d = c;
return *this;
}
customIO &operator>>(double &d) {
scanf("%lf", &d);
return *this;
}
customIO &operator>>(std::string &d) {
d.clear();
cueing();
do
d.push_back(c);
while (get_c(), !vacant());
return *this;
}
template <class T> T input() {
T d;
*this >> d;
return d;
}
// out
template <class T>
auto operator<<(T d) ->
typename std::enable_if<std::is_signed<T>::value, customIO &>::type {
c = 0;
f = 0;
if (d < static_cast<T>(0))
f = 1, d = -d;
while (d)
buf[c++] = itoc[d % 10], d /= 10;
if (!c)
buf[c++] = itoc[0];
if (f)
put_c('-');
while (c--)
put_c(buf[c]);
return *this;
}
template <class T>
auto operator<<(T d) ->
typename std::enable_if<!std::is_signed<T>::value, customIO &>::type {
c = 0;
while (d)
buf[c++] = itoc[d % 10], d /= 10;
if (!c)
buf[c++] = itoc[0];
while (c--)
put_c(buf[c]);
return *this;
}
customIO &operator<<(char d) {
put_c(d);
return *this;
}
customIO &operator<<(double d) {
printf("%f", d);
return *this;
}
customIO &operator<<(const std::string &d) {
for (const auto e : d)
put_c(e);
return *this;
}
customIO &operator<<(const char *d) {
while (*d != '\0')
put_c(*(d++));
return *this;
}
void endl() { put_c('\n'); }
void space() { put_c(' '); }
} IO;
using int32 = std::int_fast32_t;
using int64 = std::int_fast64_t;
using uint32 = std::uint_fast32_t;
using uint64 = std::uint_fast64_t;
using intl32 = std::int_least32_t;
using intl64 = std::int_least64_t;
using uintl32 = std::uint_least32_t;
using uintl64 = std::uint_least64_t;
#include <algorithm>
#include <cassert>
#include <cstdint>
#include <functional>
#include <iterator>
#include <utility>
#include <vector>
template <class T>
using ComparessDefaultContainer = std::vector<T, std::allocator<T>>;
template <class T = std::int_fast64_t,
template <class> class Container = ComparessDefaultContainer,
class Compare = std::less<typename Container::value_type>>
class Compress {
public:
using container_type = Container<T>;
using value_compare = Compare;
using value_type = typename container_type::value_type;
using reference = typename container_type::reference;
using const_reference = typename container_type::const_reference;
using size_type = typename container_type::size_type;
protected:
container_type c;
value_compare comp;
public:
Compress() : c(), comp() {}
explicit Compress(const value_compare &x) : comp(x) {}
explicit Compress(const value_compare &x, const container_type &other)
: c(other), comp(x) {
build();
}
explicit Compress(const value_compare &x, container_type &&other)
: c(std::move(other)), comp(x) {
build();
}
size_type size() const { return c.size(); }
bool empty() const { return c.empty(); }
size_type zip(const value_type &x) const {
const auto t = std::upper_bound(c.begin(), c.end(), x, comp);
assert(t != c.begin());
return static_cast<size_type>(std::distance(c.begin(), t) - 1);
}
size_type operator()(const value_type &x) const { return zip(x); }
const_reference unzip(const size_type x) const {
assert(x < size());
return c[x];
}
const_reference operator[](const size_type x) const { return unzip(x); }
void push(const value_type &x) { c.push_back(x); }
void push(value_type &&x) { c.push_back(std::move(x)); }
template <class... Args> void emplace(Args &&... args) {
c.emplace_back(std::forward<Args>(args)...);
}
void build() {
std::sort(c.begin(), c.end(), comp);
c.erase(std::unique(c.begin(), c.end()), c.end());
}
};
#include<vector>
#include<string>
#include<array>
#include<utility>
int main() {
const auto n = IO.input<uint32>();
std::vector<uint32> a(n);
for (auto &e : a)IO >> e;
Compress<std::pair<uint32, uint32>> c;
{
uint32 cur = 0;
for (const auto i : irange<>(0, n))
if (smaxi(cur, a[i]))
c.emplace(a[i], i);
}
c.emplace(0, 0);
c.build();
std::vector<uint64> imos(c.size(), 0);
std::vector<uint64> ans(n, 0);
for (const auto e : a) {
const auto t = c(std::make_pair(e, n));
ans[c[t + 1].second] += e - c[t].first;
if(t) imos[t-1]++;
}
for (const auto i : irange<>(0, c.size() - 1).rev())
imos[i] += imos[i + 1];
for (const auto i : irange<>(1, c.size())) {
ans[c[i].second] += imos[i-1] * (c[i].first - c[i - 1].first);
}
for (const auto e : ans)
IO << e << '\n';
return 0;
}
| a.cc:250:67: error: template argument 1 is invalid
250 | class Compare = std::less<typename Container::value_type>>
| ^~
a.cc:251:16: error: definition of 'class Compress' inside template parameter list
251 | class Compress {
| ^
a.cc:300:2: error: expected '>' before ';' token
300 | };
| ^
a.cc:300:2: error: expected unqualified-id before ';' token
a.cc: In function 'int main()':
a.cc:309:9: error: 'Compress' was not declared in this scope
309 | Compress<std::pair<uint32, uint32>> c;
| ^~~~~~~~
a.cc:309:42: error: expected primary-expression before '>' token
309 | Compress<std::pair<uint32, uint32>> c;
| ^~
a.cc:309:45: error: 'c' was not declared in this scope
309 | Compress<std::pair<uint32, uint32>> c;
| ^
|
s445393681 | p03801 | C++ | //#define NDEBUG
#define _CRT_SECURE_NO_WARNINGS
#include <array>
#include <cstddef>
#include <cstdint>
#include <cstdio>
#include <limits>
#include <memory>
#include <string>
#include <type_traits>
template <class Integral> class Rirange;
template <class Integral = std::size_t> class irange {
public:
using value_type = Integral;
using reference = value_type &;
using const_reference = const value_type &;
class irangeitr {
friend irange;
value_type i;
irangeitr(const value_type x) noexcept : i(x) {}
public:
void operator++() noexcept { ++i; }
value_type &operator*() noexcept { return i; }
const_reference operator*() const noexcept { return i; }
bool operator!=(const irangeitr &x) const noexcept { return i < x.i; }
};
private:
const value_type f, l;
public:
irange(const value_type first, const value_type last) noexcept
: f(first), l(last) {}
irangeitr begin() const noexcept { return irangeitr(f); }
irangeitr end() const noexcept { return irangeitr(l); }
Rirange<value_type> rev() const noexcept {
return Rirange<value_type>(l - 1, f - 1);
}
};
template <class Integral = std::size_t> class Rirange {
public:
using value_type = Integral;
using reference = value_type &;
using const_reference = const value_type &;
class Rirangeitr {
friend Rirange;
value_type i;
Rirangeitr(const value_type x) noexcept : i(x) {}
public:
void operator++() noexcept { --i; }
reference operator*() noexcept { return i; }
const_reference operator*() const noexcept { return i; }
bool operator!=(const Rirangeitr &x) const noexcept {
return (!~x.i && ~i) || x.i < i;
}
};
private:
const value_type f, l;
public:
Rirange(const value_type x, const value_type y) noexcept : f(x), l(y) {}
Rirangeitr begin() const noexcept { return Rirangeitr(f); }
Rirangeitr end() const noexcept { return Rirangeitr(l); }
irange<value_type> rev() const noexcept {
return irange<value_type>(l + 1, f + 1);
}
};
template <class T> bool maxi(T &a, const T &b) {
if (b < a)
return 0;
a = b;
return 1;
}
template <class T> bool mini(T &a, const T &b) {
if (a < b)
return 0;
a = b;
return 1;
}
template <class T> bool smaxi(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool smini(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
struct customIO {
int c;
bool f;
std::array<int, 30> buf;
const std::array<int, 10> itoc;
std::array<std::uint_least8_t, 256> ctoi_base;
const std::uint_least8_t *const ctoi;
void get_c() { c = fgetc(stdin); }
void put_c(int x) { fputc(x, stdout); }
bool vacant() { return c == ' ' || c == '\n'; }
operator int() { return 0; }
explicit customIO()
: itoc({ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' }),
ctoi(std::addressof(ctoi_base[-static_cast<std::int_fast16_t>(
std::numeric_limits<char>::min())])) {
for (std::uint_least8_t i = 0; i < 10; ++i)
ctoi_base[static_cast<int>("0123456789"[i]) -
static_cast<std::int_fast16_t>(
std::numeric_limits<char>::min())] = i;
}
// in
void cueing() {
while (get_c(), vacant())
;
}
template <class T>
auto operator>>(T &d) ->
typename std::enable_if<std::is_signed<T>::value, customIO &>::type {
d = 0;
f = 0;
cueing();
if (c == '-')
f = 1, get_c();
do
d = d * 10 + ctoi[c];
while (get_c(), !vacant());
if (f)
d = -d;
return *this;
}
template <class T>
auto operator>>(T &d) ->
typename std::enable_if<!std::is_signed<T>::value, customIO &>::type {
d = 0;
cueing();
do
d = d * 10 + ctoi[c];
while (get_c(), !vacant());
return *this;
}
customIO &operator>>(char &d) {
cueing();
d = c;
return *this;
}
customIO &operator>>(double &d) {
scanf("%lf", &d);
return *this;
}
customIO &operator>>(std::string &d) {
d.clear();
cueing();
do
d.push_back(c);
while (get_c(), !vacant());
return *this;
}
template <class T> T input() {
T d;
*this >> d;
return d;
}
// out
template <class T>
auto operator<<(T d) ->
typename std::enable_if<std::is_signed<T>::value, customIO &>::type {
c = 0;
f = 0;
if (d < static_cast<T>(0))
f = 1, d = -d;
while (d)
buf[c++] = itoc[d % 10], d /= 10;
if (!c)
buf[c++] = itoc[0];
if (f)
put_c('-');
while (c--)
put_c(buf[c]);
return *this;
}
template <class T>
auto operator<<(T d) ->
typename std::enable_if<!std::is_signed<T>::value, customIO &>::type {
c = 0;
while (d)
buf[c++] = itoc[d % 10], d /= 10;
if (!c)
buf[c++] = itoc[0];
while (c--)
put_c(buf[c]);
return *this;
}
customIO &operator<<(char d) {
put_c(d);
return *this;
}
customIO &operator<<(double d) {
printf("%f", d);
return *this;
}
customIO &operator<<(const std::string &d) {
for (const auto e : d)
put_c(e);
return *this;
}
customIO &operator<<(const char *d) {
while (*d != '\0')
put_c(*(d++));
return *this;
}
void endl() { put_c('\n'); }
void space() { put_c(' '); }
} IO;
using int32 = std::int_fast32_t;
using int64 = std::int_fast64_t;
using uint32 = std::uint_fast32_t;
using uint64 = std::uint_fast64_t;
using intl32 = std::int_least32_t;
using intl64 = std::int_least64_t;
using uintl32 = std::uint_least32_t;
using uintl64 = std::uint_least64_t;
#include <algorithm>
#include <cassert>
#include <cstdint>
#include <functional>
#include <utility>
#include <vector>
template <typename T = std::int_fast64_t, class Container = std::vector<T>,
class Compare = std::less<typename Container::value_type>>
class Compress {
public:
using container_type = Container;
using value_compare = Compare;
using value_type = typename container_type::value_type;
using reference = typename container_type::reference;
using const_reference = typename container_type::const_reference;
using size_type = typename container_type::size_type;
protected:
container_type c;
value_compare comp;
public:
explicit Compress(const value_compare &x = value_compare()) : comp(x) {}
explicit Compress(const container_type &x,
const value_compare &y = value_compare())
: c(x), comp(y) {
build();
}
explicit Compress(container_type &&x,
const value_compare &y = value_compare())
: c(std::move(x)), comp(y) {
build();
}
bool empty() const { return c.empty(); }
size_type size() const { return c.size(); }
void push(const value_type &x) { c.push_back(x); }
void push(value_type &&x) { c.push_back(std::move(x)); }
template <class... Args> void emplace(Args &&... args) {
c.emplace_back(std::forward<Args>(args)...);
}
void build() {
std::sort(c.begin(), c.end(), comp);
c.erase(std::unique(c.begin(), c.end()), c.end());
}
size_type zip(const value_type &x) const {
return std::upper_bound(c.begin(), c.end(), x, comp) - c.begin() - 1;
}
size_type operator()(const value_type &x) const { return zip(x); }
const_reference unzip(const size_type x) const {
return x < size() ? c[x] : c.back();
}
const_reference operator[](const size_type x) const { return unzip(x); }
};
#include<vector>
#include<string>
#include<array>
#include<utility>
int main() {
const auto n = IO.input<uint32>();
std::vector<uint32> a(n);
for (auto &e : a)IO >> e;
Compress<std::pair<uint32,uint32>> c;
{
uint32 cur = 0;
for (const auto i : irange<>(0, n))
if (smaxi(cur, a[i]))
c.emplace(a[i], i);
}
c.build();
std::vector<uint64> imos(c.size(), 0);
std::vector<uint64> ans(n, 0);
for (const auto e : a) {
const auto t = c(std::make_pair(e, n));
ans[c[t].second] += e - c[t].first;
imos[t]++;
}
for (const auto i : irange<>(0, c.size()-1).rev())
imos[i] += imos[i + 1];
return;
for (const auto i : irange<>(0, c.size())) {
ans[c[i].second] += imos[i] * (c[i].first - (i ? c[i - 1].first : 0));
}
for (const auto e : ans)
IO << e << '\n';
return 0;
} | a.cc: In function 'int main()':
a.cc:315:9: error: return-statement with no value, in function returning 'int' [-fpermissive]
315 | return;
| ^~~~~~
|
s655137138 | p03801 | C++ | //#define NDEBUG
#define _CRT_SECURE_NO_WARNINGS
#include <array>
#include <cstddef>
#include <cstdint>
#include <cstdio>
#include <limits>
#include <memory>
#include <string>
#include <type_traits>
template <class Integral> class Rirange;
template <class Integral = std::size_t> class irange {
public:
using value_type = Integral;
using reference = value_type &;
using const_reference = const value_type &;
class irangeitr {
friend irange;
value_type i;
irangeitr(const value_type x) noexcept : i(x) {}
public:
void operator++() noexcept { ++i; }
value_type &operator*() noexcept { return i; }
const_reference operator*() const noexcept { return i; }
bool operator!=(const irangeitr &x) const noexcept { return i < x.i; }
};
private:
const value_type f, l;
public:
irange(const value_type first, const value_type last) noexcept
: f(first), l(last) {}
irangeitr begin() const noexcept { return irangeitr(f); }
irangeitr end() const noexcept { return irangeitr(l); }
Rirange<value_type> rev() const noexcept {
return Rirange<value_type>(l - 1, f - 1);
}
};
template <class Integral = std::size_t> class Rirange {
public:
using value_type = Integral;
using reference = value_type &;
using const_reference = const value_type &;
class Rirangeitr {
friend Rirange;
value_type i;
Rirangeitr(const value_type x) noexcept : i(x) {}
public:
void operator++() noexcept { --i; }
reference operator*() noexcept { return i; }
const_reference operator*() const noexcept { return i; }
bool operator!=(const Rirangeitr &x) const noexcept {
return (!~x.i && ~i) || x.i < i;
}
};
private:
const value_type f, l;
public:
Rirange(const value_type x, const value_type y) noexcept : f(x), l(y) {}
Rirangeitr begin() const noexcept { return Rirangeitr(f); }
Rirangeitr end() const noexcept { return Rirangeitr(l); }
irange<value_type> rev() const noexcept {
return irange<value_type>(l + 1, f + 1);
}
};
template <class T> bool maxi(T &a, const T &b) {
if (b < a)
return 0;
a = b;
return 1;
}
template <class T> bool mini(T &a, const T &b) {
if (a < b)
return 0;
a = b;
return 1;
}
template <class T> bool smaxi(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool smini(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
struct customIO {
int c;
bool f;
std::array<int, 30> buf;
const std::array<int, 10> itoc;
std::array<std::uint_least8_t, 256> ctoi_base;
const std::uint_least8_t *const ctoi;
void get_c() { c = fgetc(stdin); }
void put_c(int x) { fputc(x, stdout); }
bool vacant() { return c == ' ' || c == '\n'; }
operator int() { return 0; }
explicit customIO()
: itoc({ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' }),
ctoi(std::addressof(ctoi_base[-static_cast<std::int_fast16_t>(
std::numeric_limits<char>::min())])) {
for (std::uint_least8_t i = 0; i < 10; ++i)
ctoi_base[static_cast<int>("0123456789"[i]) -
static_cast<std::int_fast16_t>(
std::numeric_limits<char>::min())] = i;
}
// in
void cueing() {
while (get_c(), vacant())
;
}
template <class T>
auto operator>>(T &d) ->
typename std::enable_if<std::is_signed<T>::value, customIO &>::type {
d = 0;
f = 0;
cueing();
if (c == '-')
f = 1, get_c();
do
d = d * 10 + ctoi[c];
while (get_c(), !vacant());
if (f)
d = -d;
return *this;
}
template <class T>
auto operator>>(T &d) ->
typename std::enable_if<!std::is_signed<T>::value, customIO &>::type {
d = 0;
cueing();
do
d = d * 10 + ctoi[c];
while (get_c(), !vacant());
return *this;
}
customIO &operator>>(char &d) {
cueing();
d = c;
return *this;
}
customIO &operator>>(double &d) {
scanf("%lf", &d);
return *this;
}
customIO &operator>>(std::string &d) {
d.clear();
cueing();
do
d.push_back(c);
while (get_c(), !vacant());
return *this;
}
template <class T> T input() {
T d;
*this >> d;
return d;
}
// out
template <class T>
auto operator<<(T d) ->
typename std::enable_if<std::is_signed<T>::value, customIO &>::type {
c = 0;
f = 0;
if (d < static_cast<T>(0))
f = 1, d = -d;
while (d)
buf[c++] = itoc[d % 10], d /= 10;
if (!c)
buf[c++] = itoc[0];
if (f)
put_c('-');
while (c--)
put_c(buf[c]);
return *this;
}
template <class T>
auto operator<<(T d) ->
typename std::enable_if<!std::is_signed<T>::value, customIO &>::type {
c = 0;
while (d)
buf[c++] = itoc[d % 10], d /= 10;
if (!c)
buf[c++] = itoc[0];
while (c--)
put_c(buf[c]);
return *this;
}
customIO &operator<<(char d) {
put_c(d);
return *this;
}
customIO &operator<<(double d) {
printf("%f", d);
return *this;
}
customIO &operator<<(const std::string &d) {
for (const auto e : d)
put_c(e);
return *this;
}
customIO &operator<<(const char *d) {
while (*d != '\0')
put_c(*(d++));
return *this;
}
void endl() { put_c('\n'); }
void space() { put_c(' '); }
} IO;
using int32 = std::int_fast32_t;
using int64 = std::int_fast64_t;
using uint32 = std::uint_fast32_t;
using uint64 = std::uint_fast64_t;
using intl32 = std::int_least32_t;
using intl64 = std::int_least64_t;
using uintl32 = std::uint_least32_t;
using uintl64 = std::uint_least64_t;
#include <algorithm>
#include <cassert>
#include <cstdint>
#include <functional>
#include <utility>
#include <vector>
template <typename T = std::int_fast64_t, class Container = std::vector<T>,
class Compare = std::less<typename Container::value_type>>
class Compress {
public:
using container_type = Container;
using value_compare = Compare;
using value_type = typename container_type::value_type;
using reference = typename container_type::reference;
using const_reference = typename container_type::const_reference;
using size_type = typename container_type::size_type;
protected:
container_type c;
value_compare comp;
public:
explicit Compress(const value_compare &x = value_compare()) : comp(x) {}
explicit Compress(const container_type &x,
const value_compare &y = value_compare())
: c(x), comp(y) {
build();
}
explicit Compress(container_type &&x,
const value_compare &y = value_compare())
: c(std::move(x)), comp(y) {
build();
}
bool empty() const { return c.empty(); }
size_type size() const { return c.size(); }
void push(const value_type &x) { c.push_back(x); }
void push(value_type &&x) { c.push_back(std::move(x)); }
template <class... Args> void emplace(Args &&... args) {
c.emplace_back(std::forward<Args>(args)...);
}
void build() {
std::sort(c.begin(), c.end(), comp);
c.erase(std::unique(c.begin(), c.end()), c.end());
}
size_type zip(const value_type &x) const {
return std::upper_bound(c.begin(), c.end(), x, comp) - c.begin() - 1;
}
size_type operator()(const value_type &x) const { return zip(x); }
const_reference unzip(const size_type x) const {
return x < size() ? c[x] : c.back();
}
const_reference operator[](const size_type x) const { return unzip(x); }
};
#include<vector>
#include<string>
#include<array>
#include<utility>
int main() {
const auto n = IO.input<uint32>();
std::vector<uint32> a(n);
for (auto &e : a)IO >> e;
Compress<std::pair<uint32,uint32>> c;
{
uint32 cur = 0;
for (const auto i : irange<>(0, n))
if (smaxi(cur, a[i]))
c.emplace(a[i], i);
}
c.build();
std::vector<uint64> imos(c.size(), 0);
std::vector<uint64> ans(n, 0);
for (const auto e : a) {
const auto t = c(std::make_pair(e, n));
ans[c[t].second] += e - c[t].first;
imos[t]++;
}
return;
for (const auto i : irange<>(0, c.size()-1).rev())
imos[i] += imos[i + 1];
for (const auto i : irange<>(0, c.size())) {
ans[c[i].second] += imos[i] * (c[i].first - (i ? c[i - 1].first : 0));
}
for (const auto e : ans)
IO << e << '\n';
return 0;
} | a.cc: In function 'int main()':
a.cc:313:9: error: return-statement with no value, in function returning 'int' [-fpermissive]
313 | return;
| ^~~~~~
|
s830207600 | p03801 | C++ | #include <bits/stdc++.h>
#define rep(i,n) for(long long int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long long int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define Abs(a,b) max(a,b)-min(a,b)
#define YES(condition) if(condition){cout << "YES" << endl;}else{cout << "NO" << endl;}
#define Yes(condition) if(condition){cout << "Yes" << endl;}else{cout << "No" << endl;}
#define Cout(x) cout<<(x)<<endl
#define POSSIBLE(condition) if(condition){cout << "POSSIBLE" << endl;}else{cout << "IMPOSSIBLE" << endl;}
#define Possible(condition) if(condition){cout << "Possible" << endl;}else{cout << "Impossible" << endl;}
#define possible(condition) if(condition){cout << "possible" << endl;}else{cout << "impossible" << endl;}
#define Size(n) (n).size()
typedef long long ll;
using namespace std;
const int INF = 1e9,MOD = 1e9 + 7,ohara=1e6;
const ll LINF = 1e18;
/*---------------------------------------------------------------
long long int kaizyo(long long int hh){
cmp=1;
while(hh>1){
cmp=(cmp*hh)%MOD;
hh--;
}
return cmp;
}
long long int ruizyo(long long int aa, long long int bb){
if(aa==0){
return 1;
}
else if(aa%2==0){
long long int tt=ruizyo(aa/2,bb);
return (tt*tt)%MOD;
}
else{
return (ruizyo(aa-1,bb)*bb)%MOD;
}
}フェルマ-のア
---------------------------------------------------------------
while(x!=0){
sum+=x%10;
/ x/=10;
}
各桁の和
---------------------------------------------------------------
pair<int,int> p[100000];
cin >> tmp;
p[i]=make_pair(tmp,i);
cout << p[i].second+1 << endl;//ペアの右側つまりiを出力
---------------------------------------------------------------
bool f[100001];//1000000以下の素数を調べよう!
rrep(i,2,100001){
f[i]=false;
}
rrep(i,2,100001){
if(!f[i]){
for(int j=i+i;j<=100000;j+=i){
f[j]=true;
}
}
}
for(int i=3;i<=100000;i+=2){
if(!f[i]){
c[i]++;
}
}
---------------------------------------------------------------
long long gcd(long long aaa,long long bbb){
if(bbb==0){
return aaa;
}
return gcd(bbb,aaa%bbb);
}
long long lcm(long long aaa,long long bbb){
long long g = gcd(aaa,bbb);
return aaa/g * bbb;
}左から最大公約数と最小公倍数
---------------------------------------------------------------
long long int prime_cnt[10000];
for(int i=2;i*i<=n;i++){
while(n%i==0){
n/=i;
prime_cnt[i]+=1;
}
if(n>1){
prime_cnt[n]+=1;
break;
}
}ある数nを素因数分解しましょう
---------------------------------------------------------------
debug:
cout<<"i: "<<i<<" j: "<<j<<" cnt: "<<cnt<<"\n";
---------------------------------------------------------------*/
long long int n,cnt=0,ans[ohara],a[ohara],b,c,d,cmp,cmpp,m,h,w,x,y,sum=0,pos;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl=true;
struct edge{int to,cost;};
//-------------------------↓↓↓↓↓↓------------------------
int main(void){
cin.tie(0);
ios::sync_with_stdio(false);
cin>>n;
pair<ll,ll> p[ohara];
rep(i,n){
cin>>a[i];
p[i]=make_pair(a[i],i);
}
sort(p,p+n);
reverse(p,p+n);
cmp=INF;
rep(i,n-1){
cout<<p[i].first<<
if(p[i].first!=p[i+1].first){
pos=p[i].first-p[i+1].first;
ans[min(p[i].second,cmp)]=(i+1)*pos;
cmp=INF;
}
else{
cmp=min(cmp,p[i].second);
}
}
rep(i,n){
Cout(ans[i]);
}
return 0;
}
| a.cc: In function 'int main()':
a.cc:139:12: error: expected primary-expression before 'if'
139 | if(p[i].first!=p[i+1].first){
| ^~
a.cc:144:12: error: 'else' without a previous 'if'
144 | else{
| ^~~~
|
s441162285 | p03801 | C++ | #include "bits/stdc++.h"
#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i, x, n) for(int i = x; i >= n; i--)
#define rrep(i, n) RREP(i,n,0)
#define pb push_back
#define show_table(n, k, table) rep(i,n){ rep(j,k) cout << table[i][j] << " "; cout << endl;}
using namespace std;
template<class T> inline void chmax(T& a,T const& b){a=max(a,b);}
template<class T> inline void chmin(T& a,T const& b){a=min(a,b);}
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vi = vector<ll>;
const int mod=1e9+7,INF=1<<30;
const double EPS=1e-12,PI=3.1415926535897932384626;
const ll lmod = 1e9+7,LINF=1LL<<60;
const int MAX_N = 100005;
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int N; cin >> N;
vector<Pl> a(N);
rep(i,N){
cin >> a[i].first;
a[i].second = i;
}
sort(ALL(a));
reverse(ALL(a));
vl ans(N);
int mi = INF;
rep(i,N){
mi = min(mi,int(a[i].second));
if(i<N-1 && a[i].first==a[i+1].first) continue;
ll diff;
if(i<N-1) diff = a[i].first - a[i+1].first;
else diff = a[i].first;
ans[mi] += diff * ll(i+1);
}
rep(i,N) cout << ans[i] << endl;
return 0;
} | a.cc:21:7: error: conflicting declaration 'using vi = class std::vector<long long int>'
21 | using vi = vector<ll>;
| ^~
a.cc:19:7: note: previous declaration as 'using vi = class std::vector<int>'
19 | using vi = vector<int>;
| ^~
a.cc: In function 'int main()':
a.cc:39:3: error: 'vl' was not declared in this scope; did you mean 'vi'?
39 | vl ans(N);
| ^~
| vi
a.cc:47:5: error: 'ans' was not declared in this scope; did you mean 'abs'?
47 | ans[mi] += diff * ll(i+1);
| ^~~
| abs
a.cc:49:20: error: 'ans' was not declared in this scope; did you mean 'abs'?
49 | rep(i,N) cout << ans[i] << endl;
| ^~~
| abs
|
s760846691 | p03801 | C++ | #include "bits/stdc++.h"
#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i, x, n) for(int i = x; i >= n; i--)
#define rrep(i, n) RREP(i,n,0)
#define pb push_back
#define show_table(n, k, table) rep(i,n){ rep(j,k) cout << table[i][j] << " "; cout << endl;}
using namespace std;
template<class T> inline void chmax(T& a,T const& b){a=max(a,b);}
template<class T> inline void chmin(T& a,T const& b){a=min(a,b);}
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vvi = vector<vi>;
const int mod=1e9+7,INF=1<<30;
const double EPS=1e-12,PI=3.1415926535897932384626;
const ll lmod = 1e9+7,LINF=1LL<<60;
const int MAX_N = 100005;
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int N; cin >> N;
vector<Pl> a(N);
rep(i,N){
cin >> a[i].first;
a[i].second = i;
}
sort(ALL(a));
reverse(ALL(a));
vl ans(N);
int mi = INF;
rep(i,N){
mi = min(mi,int(a[i].second));
if(i<N-1 && a[i].first==a[i+1].first) continue;
ll diff;
if(i<N-1) diff = a[i].first - a[i+1].first;
else diff = a[i].first;
ans[mi] += diff * ll(i+1);
}
rep(i,N) cout << ans[i] << endl;
return 0;
} | a.cc: In function 'int main()':
a.cc:38:3: error: 'vl' was not declared in this scope; did you mean 'vi'?
38 | vl ans(N);
| ^~
| vi
a.cc:46:5: error: 'ans' was not declared in this scope; did you mean 'abs'?
46 | ans[mi] += diff * ll(i+1);
| ^~~
| abs
a.cc:48:20: error: 'ans' was not declared in this scope; did you mean 'abs'?
48 | rep(i,N) cout << ans[i] << endl;
| ^~~
| abs
|
s519493262 | p03801 | C++ | #include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
bool cmp(const pair<int, int>& p1, const pair<int, int>& p2) {
return p1.first > p2.first;
}
int main(void) {
int n;
cin >> n;
vector <pair <int, int> > a(n);
for (int i = 0; i < n; i++) {
cin >> a[i].first;
a[i].second = i;
}
sort(a.begin(), a.end(), cmp);
vector<ll> cnt(n, 0LL);
int mini = a[0].first;
for (int i = 0; i < n - 1; i++) {
if (a[i].second < mini) {
mini = a[i].second;
}
if (a[i].first != a[i + 1].first) {
cnt[mini] += (a[i].first - a[i + 1].first) * (i + 1);
}
}
cnt[0] += a[n - 1].first * n;
for (int i = 0; i < n; i++) {
cout << cnt[i] << endl;
}
return 0;
} | a.cc: In function 'int main()':
a.cc:16:3: error: 'sort' was not declared in this scope; did you mean 'short'?
16 | sort(a.begin(), a.end(), cmp);
| ^~~~
| short
|
s868163044 | p03801 | C++ | #include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=100010;
int n,a[N],rank[N];
ll ans[N];
int cmp(int aa,int bb){
// if(a[aa]==a[bb]) return aa>bb;
return a[aa]>a[bb];
}
int main(){
scanf("%d",&n);
for(int i=1;i<=n;i++) scanf("%d",&a[i]);
for(int i=0;i<=n;i++) rank[i]=i;
sort(rank,rank+n+1,cmp);
int now,nxt=0;
ll tot1=0,tot2=0;
while(nxt<n){
now=nxt;
while(rank[nxt]>=rank[now]) tot1+=a[rank[nxt]],nxt++,tot2++;
ans[rank[now]]+=tot1-tot2*a[rank[nxt]];
tot1=tot2*a[rank[nxt]];
}
for(int i=1;i<=n;i++) printf("%lld\n",ans[i]);
return 0;
} | a.cc: In function 'int main()':
a.cc:14:31: error: reference to 'rank' is ambiguous
14 | for(int i=0;i<=n;i++) rank[i]=i;
| ^~~~
In file included from /usr/include/c++/14/bits/stl_pair.h:60,
from /usr/include/c++/14/bits/stl_algobase.h:64,
from /usr/include/c++/14/algorithm:60,
from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
from a.cc:1:
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
1437 | struct rank
| ^~~~
a.cc:5:12: note: 'int rank [100010]'
5 | int n,a[N],rank[N];
| ^~~~
a.cc:15:14: error: reference to 'rank' is ambiguous
15 | sort(rank,rank+n+1,cmp);
| ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
1437 | struct rank
| ^~~~
a.cc:5:12: note: 'int rank [100010]'
5 | int n,a[N],rank[N];
| ^~~~
a.cc:15:19: error: reference to 'rank' is ambiguous
15 | sort(rank,rank+n+1,cmp);
| ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
1437 | struct rank
| ^~~~
a.cc:5:12: note: 'int rank [100010]'
5 | int n,a[N],rank[N];
| ^~~~
a.cc:20:23: error: reference to 'rank' is ambiguous
20 | while(rank[nxt]>=rank[now]) tot1+=a[rank[nxt]],nxt++,tot2++;
| ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
1437 | struct rank
| ^~~~
a.cc:5:12: note: 'int rank [100010]'
5 | int n,a[N],rank[N];
| ^~~~
a.cc:20:34: error: reference to 'rank' is ambiguous
20 | while(rank[nxt]>=rank[now]) tot1+=a[rank[nxt]],nxt++,tot2++;
| ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
1437 | struct rank
| ^~~~
a.cc:5:12: note: 'int rank [100010]'
5 | int n,a[N],rank[N];
| ^~~~
a.cc:20:53: error: reference to 'rank' is ambiguous
20 | while(rank[nxt]>=rank[now]) tot1+=a[rank[nxt]],nxt++,tot2++;
| ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
1437 | struct rank
| ^~~~
a.cc:5:12: note: 'int rank [100010]'
5 | int n,a[N],rank[N];
| ^~~~
a.cc:21:21: error: reference to 'rank' is ambiguous
21 | ans[rank[now]]+=tot1-tot2*a[rank[nxt]];
| ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
1437 | struct rank
| ^~~~
a.cc:5:12: note: 'int rank [100010]'
5 | int n,a[N],rank[N];
| ^~~~
a.cc:21:45: error: reference to 'rank' is ambiguous
21 | ans[rank[now]]+=tot1-tot2*a[rank[nxt]];
| ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
1437 | struct rank
| ^~~~
a.cc:5:12: note: 'int rank [100010]'
5 | int n,a[N],rank[N];
| ^~~~
a.cc:22:29: error: reference to 'rank' is ambiguous
22 | tot1=tot2*a[rank[nxt]];
| ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
1437 | struct rank
| ^~~~
a.cc:5:12: note: 'int rank [100010]'
5 | int n,a[N],rank[N];
| ^~~~
|
s640400325 | p03801 | C++ | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod 1e9+7
__attribute__((constructor))
void initial() {
cin.tie(0);
ios::sync_with_stdio(false);
}
struct pa {
int i;
int num;
bool operator<(const pa& right) const {
return num == right.num ? i < right.i : num < right.num;
}
};
int main() {
ll n, ans[100001] = {};
cin >> n;
pa a[n];
rep(i, 0, n) {
cin >> a[i].num;
a[i].i = i;
}
sort(a, a + n);
ll z = a[n - 1].num, zz = z, m = 1145141919;
dep(i, n - 2, 0) {
if(z != a[i].num) {
m = min(m, a[i + 1].i);
ans[m] += (z - a[i].num) * (n - i - 1);
zz = z;
z = a[i].num;
}
}
m = min(m, a[0].i);
ans[m] += (zz - a[0].num) * n;
rep(i, 0, n) {
cout << ans[i] << endl;
}
}
| a.cc: In function 'int main()':
a.cc:39:14: error: no matching function for call to 'min(ll&, int&)'
39 | m = min(m, a[i + 1].i);
| ~~~^~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
233 | min(const _Tp& __a, const _Tp& __b)
| ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: template argument deduction/substitution failed:
a.cc:39:14: note: deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
39 | m = min(m, a[i + 1].i);
| ~~~^~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
281 | min(const _Tp& __a, const _Tp& __b, _Compare __comp)
| ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
5686 | min(initializer_list<_Tp> __l)
| ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
5696 | min(initializer_list<_Tp> __l, _Compare __comp)
| ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: template argument deduction/substitution failed:
a.cc:39:14: note: mismatched types 'std::initializer_list<_Tp>' and 'long long int'
39 | m = min(m, a[i + 1].i);
| ~~~^~~~~~~~~~~~~~~
a.cc:46:10: error: no matching function for call to 'min(ll&, int&)'
46 | m = min(m, a[0].i);
| ~~~^~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
233 | min(const _Tp& __a, const _Tp& __b)
| ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: template argument deduction/substitution failed:
a.cc:46:10: note: deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
46 | m = min(m, a[0].i);
| ~~~^~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
281 | min(const _Tp& __a, const _Tp& __b, _Compare __comp)
| ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate expects 3 arguments, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
5686 | min(initializer_list<_Tp> __l)
| ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
5696 | min(initializer_list<_Tp> __l, _Compare __comp)
| ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: template argument deduction/substitution failed:
a.cc:46:10: note: mismatched types 'std::initializer_list<_Tp>' and 'long long int'
46 | m = min(m, a[0].i);
| ~~~^~~~~~~~~~~
|
s354859410 | p03801 | C++ | #include<bits/stdc++.h>
using namespace std;
long long N;
long long a[100005];
long long ans[100005];
// val , num
map<long long, long long> memo;
// pos
vector<long long> V;
int main(){
cin >> N;
for(long long i = 0; i < N; i++){
cin >> a[i];
memo[a[i]]++;
}
V.push_back(0);
for(long long i = 1; i < N; i++){
if(a[V.back()] < a[i]){
V.push_back(i);
}
}
for(long long i = V.size() - 2; i >= 0; i--){
while(memo.rbegin()->first > a[V[i]]){
ans[V[i+1]] += (memo.rbegin()->first - a[V[i]])*memo.rbegin()->second;
memo[a[V[i]]] += memo.rbegin()->second;
memo.erase(memo.rbegin()->first);
}
}
for(auto m : memo){
ans[0] += r.first * m.second;
}
//ans[V[0]] += memo.begin()->second;
for(long long i = 0; i < N; i++){
cout << ans[i] << endl;
}
}
| a.cc: In function 'int main()':
a.cc:34:27: error: 'r' was not declared in this scope
34 | ans[0] += r.first * m.second;
| ^
|
s948229149 | p03801 | C++ | #include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
ll N;
cin >> N;
ll a[N];
for(ll i = 0; i < N; i++)
cin >> a[i];
map<ll, vector<ll> > mp;
for(ll i = 0; i < N; i++) {
mp[a[i]].push_back(i + 1);
}
cout << mp << endl;
vector< pair<ll, vector<ll> > > v;
for(auto i: mp) {
v.push_back(make_pair(i.first, i.second));
}
reverse(v.begin(), v.end());
ll ans[N + 1];
for(ll i = 0; i < N + 1; i++) {
ans[i] = 0;
}
ll cnt = 0;
for(ll i = 0; i < v.size(); i++) {
cnt += v[i].second.size();
if(i == v.size() - 1) {
ans[v[i].second[0]] += (v[i].first - 0) * cnt;
continue;
}
ans[v[i].second[0]] += (v[i].first - v[i+1].first) * cnt;
}
for(ll i = 1; i <= N; i++) {
cout << ans[i] << endl;
}
}
| a.cc: In function 'int main()':
a.cc:20:8: error: no match for 'operator<<' (operand types are 'std::ostream' {aka 'std::basic_ostream<char>'} and 'std::map<long long int, std::vector<long long int> >')
20 | cout << mp << endl;
| ~~~~ ^~ ~~
| | |
| | std::map<long long int, std::vector<long long int> >
| std::ostream {aka std::basic_ostream<char>}
In file included from /usr/include/c++/14/istream:41,
from /usr/include/c++/14/sstream:40,
from /usr/include/c++/14/complex:45,
from /usr/include/c++/14/ccomplex:39,
from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:127,
from a.cc:1:
/usr/include/c++/14/ostream:116:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(__ostream_type& (*)(__ostream_type&)) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
116 | operator<<(__ostream_type& (*__pf)(__ostream_type&))
| ^~~~~~~~
/usr/include/c++/14/ostream:116:36: note: no known conversion for argument 1 from 'std::map<long long int, std::vector<long long int> >' to 'std::basic_ostream<char>::__ostream_type& (*)(std::basic_ostream<char>::__ostream_type&)' {aka 'std::basic_ostream<char>& (*)(std::basic_ostream<char>&)'}
116 | operator<<(__ostream_type& (*__pf)(__ostream_type&))
| ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/ostream:125:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(__ios_type& (*)(__ios_type&)) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>; __ios_type = std::basic_ios<char>]'
125 | operator<<(__ios_type& (*__pf)(__ios_type&))
| ^~~~~~~~
/usr/include/c++/14/ostream:125:32: note: no known conversion for argument 1 from 'std::map<long long int, std::vector<long long int> >' to 'std::basic_ostream<char>::__ios_type& (*)(std::basic_ostream<char>::__ios_type&)' {aka 'std::basic_ios<char>& (*)(std::basic_ios<char>&)'}
125 | operator<<(__ios_type& (*__pf)(__ios_type&))
| ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
/usr/include/c++/14/ostream:135:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(std::ios_base& (*)(std::ios_base&)) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
135 | operator<<(ios_base& (*__pf) (ios_base&))
| ^~~~~~~~
/usr/include/c++/14/ostream:135:30: note: no known conversion for argument 1 from 'std::map<long long int, std::vector<long long int> >' to 'std::ios_base& (*)(std::ios_base&)'
135 | operator<<(ios_base& (*__pf) (ios_base&))
| ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
/usr/include/c++/14/ostream:174:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long int) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
174 | operator<<(long __n)
| ^~~~~~~~
/usr/include/c++/14/ostream:174:23: note: no known conversion for argument 1 from 'std::map<long long int, std::vector<long long int> >' to 'long int'
174 | operator<<(long __n)
| ~~~~~^~~
/usr/include/c++/14/ostream:178:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long unsigned int) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
178 | operator<<(unsigned long __n)
| ^~~~~~~~
/usr/include/c++/14/ostream:178:32: note: no known conversion for argument 1 from 'std::map<long long int, std::vector<long long int> >' to 'long unsigned int'
178 | operator<<(unsigned long __n)
| ~~~~~~~~~~~~~~^~~
/usr/include/c++/14/ostream:182:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(bool) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
182 | operator<<(bool __n)
| ^~~~~~~~
/usr/include/c++/14/ostream:182:23: note: no known conversion for argument 1 from 'std::map<long long int, std::vector<long long int> >' to 'bool'
182 | operator<<(bool __n)
| ~~~~~^~~
In file included from /usr/include/c++/14/ostream:1022:
/usr/include/c++/14/bits/ostream.tcc:96:5: note: candidate: 'std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(short int) [with _CharT = char; _Traits = std::char_traits<char>]'
96 | basic_ostream<_CharT, _Traits>::
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/ostream.tcc:97:22: note: no known conversion for argument 1 from 'std::map<long long int, std::vector<long long int> >' to 'short int'
97 | operator<<(short __n)
| ~~~~~~^~~
/usr/include/c++/14/ostream:189:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(short unsigned int) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
189 | operator<<(unsigned short __n)
| ^~~~~~~~
/usr/include/c++/14/ostream:189:33: note: no known conversion for argument 1 from 'std::map<long long int, std::vector<long long int> >' to 'short unsigned int'
189 | operator<<(unsigned short __n)
| ~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/ostream.tcc:110:5: note: candidate: 'std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(int) [with _CharT = char; _Traits = std::char_traits<char>]'
110 | basic_ostream<_CharT, _Traits>::
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/ostream.tcc:111:20: note: no known conversion for argument 1 from 'std::map<long long int, std::vector<long long int> >' to 'int'
111 | operator<<(int __n)
| ~~~~^~~
/usr/include/c++/14/ostream:200:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(unsigned int) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
200 | operator<<(unsigned int __n)
| ^~~~~~~~
/usr/include/c++/14/ostream:200:31: note: no known conversion for argument 1 from 'std::map<long long int, std::vector<long long int> >' to 'unsigned int'
200 | operator<<(unsigned int __n)
| ~~~~~~~~~~~~~^~~
/usr/include/c++/14/ostream:211:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long long int) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
211 | operator<<(long long __n)
| ^~~~~~~~
/usr/include/c++/14/ostream:211:28: note: no known conversion for argument 1 from 'std::map<long long int, std::vector<long long int> >' to 'long long int'
211 | operator<<(long long __n)
| ~~~~~~~~~~^~~
/usr/include/c++/14/ostream:215:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long long unsigned int) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
215 | operator<<(unsigned long long __n)
| ^~~~~~~~
/usr/include/c++/14/ostream:215:37: note: no known conversion for argument 1 from 'std::map<long long int, std::vector<long long int> >' to 'long long unsigned int'
215 | operator<<(unsigned long long __n)
| ~~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/ostream:231:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(double) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
231 | operator<<(double __f)
| ^~~~~~~~
/usr/include/c++/14/ostream:231:25: note: no known conversion for argument 1 from 'std::map<long long int, std::vector<long long int> >' to 'double'
231 | operator<<(double __f)
| ~~~~~~~^~~
/usr/include/c++/14/ostream:235:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(float) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
235 | operator<<(float __f)
| ^~~~~~~~
/usr/include/c++/14/ostream:235:24: note: no known conversion for argument 1 from 'std::map<long long int, std::vector<long long int> >' to 'float'
235 | operator<<(float __f)
| ~~~~~~^~~
/usr/include/c++/14/ostream:243:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long double) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
243 | operator<<(long double __f)
| ^~~~~~~~
/usr/include/c++/14/ostream:243:30: note: no known conversion for argument 1 from 'std::map<long long int, std::vector<long long int> >' to 'long double'
243 | operator<<(long double __f)
| ~~~~~~~~~~~~^~~
/usr/include/c++/14/ostream:301:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(const void*) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
301 | operator<<(const void* __p)
| ^~~~~~~~
/usr/include/c++/14/ostream:301:30: note: no known conversion for argument 1 from 'std::map<long long int, std::vector<long long int> >' to 'co |
s722420141 | p03801 | C++ | #include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
using namespace std;
#define mod 1000000007
int main()
{
int n;
cin >> n;
int a[100001];
map<int, int> cnt;
vector<pair<int, int> > tmp;
for(int i = 1; i <= n; i++){
cin >> a[i];
if(cnt.find(a[i]) == cnt.end()){
cnt[a[i]] = 1;
tmp.push_back(make_pair(a[i], i));
}else{
cnt[a[i]]++;
}
}
sort(tmp.begin(), tmp.end());
reverse(tmp.begin(), tmp.end());
long long int checkednum = 0;
long long int ans[100001] = {};
tmp.push_back(make_pair(0, 0));
long long int minindex = n;
for(int i = 0; i < tmp.size() - 1; i++){
long long int now = tmp[i].first;
long long int next = tmp[i + 1].first;
minindex = min(minindex, tmp[i].second);
checkednum += cnt[now];
ans[minindex] += (now - next) * checkednum;
}
for(int i = 1; i <= n; i++){
cout << ans[i] << endl;
}
} | a.cc: In function 'int main()':
a.cc:48:31: error: no matching function for call to 'min(long long int&, int&)'
48 | minindex = min(minindex, tmp[i].second);
| ~~~^~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/string:51,
from /usr/include/c++/14/bits/locale_classes.h:40,
from /usr/include/c++/14/bits/ios_base.h:41,
from /usr/include/c++/14/ios:44,
from /usr/include/c++/14/ostream:40,
from /usr/include/c++/14/iostream:41,
from a.cc:2:
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
233 | min(const _Tp& __a, const _Tp& __b)
| ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: template argument deduction/substitution failed:
a.cc:48:31: note: deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
48 | minindex = min(minindex, tmp[i].second);
| ~~~^~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
281 | min(const _Tp& __a, const _Tp& __b, _Compare __comp)
| ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61,
from a.cc:6:
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
5686 | min(initializer_list<_Tp> __l)
| ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
5696 | min(initializer_list<_Tp> __l, _Compare __comp)
| ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: template argument deduction/substitution failed:
a.cc:48:31: note: mismatched types 'std::initializer_list<_Tp>' and 'long long int'
48 | minindex = min(minindex, tmp[i].second);
| ~~~^~~~~~~~~~~~~~~~~~~~~~~~~
|
s406514514 | p03801 | C++ | #include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <numeric>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <time.h>
#include <limits.h>
using namespace std;
typedef long long ll;
#define pl pair<ll,ll>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define foreach(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); itr++)
#define dbg(x) cout << #x"="<< (x) << endl
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back(a)
#define in(x) cin >> x;
#define all(x) (x).begin(), (x).end()
#define INF 2147483600
#define fi first
#define se second
ll n,j=LLONG_MAX;
vector<pl>v;
void update(vector<ll> &ans, int i){
j=min(j,v[i].se);
if(i==0){
ans[v[i].se]+=(n-i)*(v[i].fi);
return;
}
ans[v[i].se]+=(n-i)*(v[i].fi-v[i-1].fi);
update(ans,i-1);
}
int main(){
cin>>n;
vector<ll>a(n),ans(n);
rep(i,n)cin>>a[i];
rep(i,n)v.pb(mp(a[i],i));
sort(all(v));
update(ans,n-1);
rep(i,n){
cout<<ans[i]<<endl;
}
return 0;
}#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <numeric>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <time.h>
#include <limits.h>
using namespace std;
typedef long long ll;
#define pl pair<ll,ll>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define foreach(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); itr++)
#define dbg(x) cout << #x"="<< (x) << endl
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back(a)
#define in(x) cin >> x;
#define all(x) (x).begin(), (x).end()
#define INF 2147483600
#define fi first
#define se second
ll n,j=LLONG_MAX;
vector<pl>v;
void update(vector<ll> &ans, int i){
j=min(j,v[i].se);
if(i==0){
ans[v[i].se]+=(n-i)*(v[i].fi);
return;
}
ans[v[i].se]+=(n-i)*(v[i].fi-v[i-1].fi);
update(ans,i-1);
}
int main(){
cin>>n;
vector<ll>a(n),ans(n);
rep(i,n)cin>>a[i];
rep(i,n)v.pb(mp(a[i],i));
sort(all(v));
update(ans,n-1);
rep(i,n){
cout<<ans[i]<<endl;
}
return 0;
} | a.cc:53:2: error: stray '#' in program
53 | }#include <iostream>
| ^
a.cc:53:3: error: 'include' does not name a type
53 | }#include <iostream>
| ^~~~~~~
a.cc:80:4: error: redefinition of 'll n'
80 | ll n,j=LLONG_MAX;
| ^
a.cc:28:4: note: 'll n' previously declared here
28 | ll n,j=LLONG_MAX;
| ^
a.cc:80:6: error: redefinition of 'll j'
80 | ll n,j=LLONG_MAX;
| ^
a.cc:28:6: note: 'll j' previously defined here
28 | ll n,j=LLONG_MAX;
| ^
a.cc:81:11: error: redefinition of 'std::vector<std::pair<long long int, long long int> > v'
81 | vector<pl>v;
| ^
a.cc:29:11: note: 'std::vector<std::pair<long long int, long long int> > v' previously declared here
29 | vector<pl>v;
| ^
a.cc:82:6: error: redefinition of 'void update(std::vector<long long int>&, int)'
82 | void update(vector<ll> &ans, int i){
| ^~~~~~
a.cc:30:6: note: 'void update(std::vector<long long int>&, int)' previously defined here
30 | void update(vector<ll> &ans, int i){
| ^~~~~~
a.cc:93:5: error: redefinition of 'int main()'
93 | int main(){
| ^~~~
a.cc:41:5: note: 'int main()' previously defined here
41 | int main(){
| ^~~~
|
s694229225 | p03801 | C++ | #include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <numeric>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <time.h>
using namespace std;
typedef long long ll;
#define pl pair<ll,ll>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define foreach(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); itr++)
#define dbg(x) cout << #x"="<< (x) << endl
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back(a)
#define in(x) cin >> x;
#define all(x) (x).begin(), (x).end()
#define INF 2147483600
#define fi first
#define se second
ll n,j=LLONG_MAX;
vector<pl>v;
void update(vector<ll> &ans, int i){
j=min(j,v[i].se);
if(i==0){
ans[v[i].se]+=(n-i)*(v[i].fi);
return;
}
ans[v[i].se]+=(n-i)*(v[i].fi-v[i-1].fi);
update(ans,i-1);
}
int main(){
cin>>n;
vector<ll>a(n),ans(n);
rep(i,n)cin>>a[i];
rep(i,n)v.pb(mp(a[i],i));
sort(all(v));
update(ans,n-1);
rep(i,n){
cout<<ans[i]<<endl;
}
return 0;
} | a.cc:27:8: error: 'LLONG_MAX' was not declared in this scope
27 | ll n,j=LLONG_MAX;
| ^~~~~~~~~
a.cc:10:1: note: 'LLONG_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
9 | #include <queue>
+++ |+#include <climits>
10 | #include <time.h>
|
s338004279 | p03801 | C++ | hoge | a.cc:1:1: error: 'hoge' does not name a type
1 | hoge
| ^~~~
|
s455039247 | p03801 | C++ | #include <iostream>
#include <utility>
#include <algorithm>
#include <climits>
int main(int argc, char **argv) {
long long int n=0;
std::cin >> n;
long long int *ret = new long long int[n];
std::vector<std::pair<long long int, long int> > v;
for(long long int i=0; i < n; i++) {
long long int a;
std::cin >> a;
v.push_back({a,i});
ret[i] = 0;
}
std::sort(v.begin(),v.end());
std::reverse(v.begin(),v.end());
long long int cur = 0;
long long int min = INT_MAX;
long long int count = 0;
while (cur < n) {
long long int next = cur;
while (next<n and v[cur].first == v[next].first) {
if (min > v[next].second) {
min = v[next].second;
}
next++;
count++;
}
if (next == n) {
ret[min] += (v[cur].first) * count;
} else {
ret[min] += (v[cur].first - v[next].first) * count;
}
cur = next;
}
for (long long int i=0; i < n; i++) {
std::cout << ret[i] << std::endl;
}
return 0;
}
| a.cc: In function 'int main(int, char**)':
a.cc:12:14: error: 'vector' is not a member of 'std'
12 | std::vector<std::pair<long long int, long int> > v;
| ^~~~~~
a.cc:5:1: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
4 | #include <climits>
+++ |+#include <vector>
5 |
a.cc:12:56: error: expected primary-expression before '>' token
12 | std::vector<std::pair<long long int, long int> > v;
| ^
a.cc:12:58: error: 'v' was not declared in this scope
12 | std::vector<std::pair<long long int, long int> > v;
| ^
|
s568904680 | p03801 | C++ | #include<bits/stdc++.h>
#define ul unsigned long
using namespace std;
int main(){
cin.tie(0);ios::sync_with_stdio(false);
ul n;ul tmp; ul m=0;
cin>>n;
vector<pair<ul,ul> >l;vector<ul long>ans(n);
l.reserve(n+1);
for(ul i=0;i<n;++i){cin>>tmp;l[i].emplace_back(make_pair(tmp,i));}
l.emplace_back(make_pair(0,n));
stable_sort(l.begin(),l.end(),[](auto a,auto b){return a.first>b.first;});
for(auto it=l.cbegin(),tar=l.cbegin();it!=l.cend()-1;){
if(tar->second>it->second)tar=it;
ans[tar->second]+=(it->first-(++it)->first)*++m;
}
for(auto x:ans)cout<< x <<'\n';cout.flush();
return 0;
} | a.cc: In function 'int main()':
a.cc:10:37: error: '__gnu_cxx::__alloc_traits<std::allocator<std::pair<long unsigned int, long unsigned int> >, std::pair<long unsigned int, long unsigned int> >::value_type' {aka 'struct std::pair<long unsigned int, long unsigned int>'} has no member named 'emplace_back'
10 | for(ul i=0;i<n;++i){cin>>tmp;l[i].emplace_back(make_pair(tmp,i));}
| ^~~~~~~~~~~~
|
s919488568 | p03801 | C++ | #include<bits/stdc++.h>
int main(){
std::cin.tie(0);
std::ios::sync_with_stdio(false);
long n;unsigned long tmp; long m=0;
std::array<std::pair<unsigned long,unsigned long> > ls;
std::cin >> n;
unsigned long long ans[n];
ls.resize(n+1);
for(long i=0; i<n; ++i) {std::cin >> tmp;ls[i]=(std::make_pair(tmp,i));}
ls[n]=(std::make_pair(0,n));
std::stable_sort(ls.begin(),ls.end(),[](auto a,auto b){return a.first>b.first;});
auto target=ls.begin();
for(auto it=ls.begin();it!=ls.cend()-1;){
if(target->second>it->second)target=it;
ans[target->second]+=(it->first-(++it)->first)*(++m);
}
for(auto x : ans) std::cout<< x <<'\n';
std::cout.flush();
return 0;
} | a.cc: In function 'int main()':
a.cc:6:53: error: wrong number of template arguments (1, should be 2)
6 | std::array<std::pair<unsigned long,unsigned long> > ls;
| ^
In file included from /usr/include/c++/14/bits/stl_algobase.h:64,
from /usr/include/c++/14/algorithm:60,
from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
from a.cc:1:
/usr/include/c++/14/bits/stl_pair.h:99:12: note: provided for 'template<class _Tp, long unsigned int _Nm> struct std::array'
99 | struct array;
| ^~~~~
a.cc:9:6: error: request for member 'resize' in 'ls', which is of non-class type 'int'
9 | ls.resize(n+1);
| ^~~~~~
a.cc:10:46: error: invalid types 'int[long int]' for array subscript
10 | for(long i=0; i<n; ++i) {std::cin >> tmp;ls[i]=(std::make_pair(tmp,i));}
| ^
a.cc:11:5: error: invalid types 'int[long int]' for array subscript
11 | ls[n]=(std::make_pair(0,n));
| ^
a.cc:12:23: error: request for member 'begin' in 'ls', which is of non-class type 'int'
12 | std::stable_sort(ls.begin(),ls.end(),[](auto a,auto b){return a.first>b.first;});
| ^~~~~
a.cc:12:34: error: request for member 'end' in 'ls', which is of non-class type 'int'
12 | std::stable_sort(ls.begin(),ls.end(),[](auto a,auto b){return a.first>b.first;});
| ^~~
a.cc:13:18: error: request for member 'begin' in 'ls', which is of non-class type 'int'
13 | auto target=ls.begin();
| ^~~~~
a.cc:14:18: error: request for member 'begin' in 'ls', which is of non-class type 'int'
14 | for(auto it=ls.begin();it!=ls.cend()-1;){
| ^~~~~
a.cc:14:33: error: request for member 'cend' in 'ls', which is of non-class type 'int'
14 | for(auto it=ls.begin();it!=ls.cend()-1;){
| ^~~~
|
s411711305 | p03801 | C++ | #include<bits/stdc++.h>
int main(){
std::cin.tie(0);
ios::sync_with_stdio(false);
long n;unsigned long tmp; long m=0;
std::array<std::pair<unsigned long,unsigned long> > ls;
std::cin >> n;
unsigned long long ans[n];
ls.resize(n+1);
for(long i=0; i<n; ++i) {std::cin >> tmp;ls[i]=(std::make_pair(tmp,i));}
ls[n]=(std::make_pair(0,n));
std::stable_sort(ls.begin(),ls.end(),[](auto a,auto b){return a.first>b.first;});
auto target=ls.begin();
for(auto it=ls.begin();it!=ls.cend()-1;){
if(target->second>it->second)target=it;
ans[target->second]+=(it->first-(++it)->first)*(++m);
}
for(auto x : ans) std::cout<< x <<'\n';
std::cout.flush();
return 0;
} | a.cc: In function 'int main()':
a.cc:4:3: error: 'ios' has not been declared
4 | ios::sync_with_stdio(false);
| ^~~
a.cc:6:53: error: wrong number of template arguments (1, should be 2)
6 | std::array<std::pair<unsigned long,unsigned long> > ls;
| ^
In file included from /usr/include/c++/14/bits/stl_algobase.h:64,
from /usr/include/c++/14/algorithm:60,
from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
from a.cc:1:
/usr/include/c++/14/bits/stl_pair.h:99:12: note: provided for 'template<class _Tp, long unsigned int _Nm> struct std::array'
99 | struct array;
| ^~~~~
a.cc:9:6: error: request for member 'resize' in 'ls', which is of non-class type 'int'
9 | ls.resize(n+1);
| ^~~~~~
a.cc:10:46: error: invalid types 'int[long int]' for array subscript
10 | for(long i=0; i<n; ++i) {std::cin >> tmp;ls[i]=(std::make_pair(tmp,i));}
| ^
a.cc:11:5: error: invalid types 'int[long int]' for array subscript
11 | ls[n]=(std::make_pair(0,n));
| ^
a.cc:12:23: error: request for member 'begin' in 'ls', which is of non-class type 'int'
12 | std::stable_sort(ls.begin(),ls.end(),[](auto a,auto b){return a.first>b.first;});
| ^~~~~
a.cc:12:34: error: request for member 'end' in 'ls', which is of non-class type 'int'
12 | std::stable_sort(ls.begin(),ls.end(),[](auto a,auto b){return a.first>b.first;});
| ^~~
a.cc:13:18: error: request for member 'begin' in 'ls', which is of non-class type 'int'
13 | auto target=ls.begin();
| ^~~~~
a.cc:14:18: error: request for member 'begin' in 'ls', which is of non-class type 'int'
14 | for(auto it=ls.begin();it!=ls.cend()-1;){
| ^~~~~
a.cc:14:33: error: request for member 'cend' in 'ls', which is of non-class type 'int'
14 | for(auto it=ls.begin();it!=ls.cend()-1;){
| ^~~~
|
s439476295 | p03801 | C++ | #include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<stack>
#include<climits>
#include<cstring>
#include<queue>
#include<map>
#include<functional>
using namespace std;
typedef unsigned long long ull;
const int INF = INT_MAX/3;
int main(){
int N;
cin >> N;
vector<ull> a(N);
vector< pair<ull, ull> > pairList;
for (int i=0;i<N;i++){
cin >> a[i];
pairList.push_back(make_pair(a[i], i+1));
}
pairList.push_back(make_pair(0, 0));
sort(pairList.begin(), pairList.end(), greater< pair<ull, ull> >());
vector<ull> count(N+1, 0ull);
int secondMin = INF;
for(int i=0;i<N;i++){
secondMin = min(secondMin, pairList[i].second);
count[secondMin] += (pairList[i].first - pairList[i+1].first)*(i+1);
}
for(int i=1;i<N+1;i++){
cout << count[i] << endl;
}
return 0;
} | a.cc: In function 'int main()':
a.cc:34:24: error: no matching function for call to 'min(int&, long long unsigned int&)'
34 | secondMin = min(secondMin, pairList[i].second);
| ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/string:51,
from /usr/include/c++/14/bits/locale_classes.h:40,
from /usr/include/c++/14/bits/ios_base.h:41,
from /usr/include/c++/14/ios:44,
from /usr/include/c++/14/ostream:40,
from /usr/include/c++/14/iostream:41,
from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
233 | min(const _Tp& __a, const _Tp& __b)
| ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: template argument deduction/substitution failed:
a.cc:34:24: note: deduced conflicting types for parameter 'const _Tp' ('int' and 'long long unsigned int')
34 | secondMin = min(secondMin, pairList[i].second);
| ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
281 | min(const _Tp& __a, const _Tp& __b, _Compare __comp)
| ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61,
from a.cc:3:
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
5686 | min(initializer_list<_Tp> __l)
| ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
5696 | min(initializer_list<_Tp> __l, _Compare __comp)
| ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: template argument deduction/substitution failed:
a.cc:34:24: note: mismatched types 'std::initializer_list<_Tp>' and 'int'
34 | secondMin = min(secondMin, pairList[i].second);
| ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
s705953231 | p03801 | C++ | #include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define debug0(x) printf("! %d\n", x);
#define debug1(x, a, b) for(int (ii)=(a);(ii)<(b);(ii++)) printf("%d: %d\n", ii, x[ii]);
#define nono(x, ite) for(__typeof((x).begin()) (ite)=(x).begin();(ite)!=(x).end();(ite++))
typedef long long ll;
const int N = 1e5 + 10;
int n, lv;
ll a[N], ans[N], gar[N];
bool vis[N];
vector<int> pos;
ll s[2][N];
void add(int id, int u, ll v) {
while (u <= n) {
s[id][u] += v;
u += u & -u;
}
}
ll get(int id, ll u) {
ll res = 0;
while (u) {
res += s[id][u];
u -= u & -u;
}
return res;
}
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%I64d", &a[i]);
gar[lv++] = a[i];
}
if(n == 1) {
printf("%I64d\n", a[i]);
return 0;
}
ll mx = 0;
pos.pb(0);
for (int i = 1; i <= n; i++) {
if (mx < a[i]) mx = a[i], pos.pb(i);
}
for (int i = 0; i < pos.size(); i++) {
vis[pos[i]] = 1;
}
sort(gar, gar + lv);
lv = unique(gar, gar + lv) - gar;
for (int i = 1; i <= n; i++) {
a[i] = lower_bound(gar, gar + lv, a[i]) - gar + 1;
}
ll tsum = 0;
int len = pos.size() - 1;
for(int i = n; i >= 1; i--) {
add(0, a[i], 1);
add(1, a[i], gar[a[i] - 1]);
if(vis[i]) {
ans[i] = (get(1, lv + 1) - get(1, a[pos[len - 1]])) - tsum - (get(0, lv + 1) - get(0, a[pos[len - 1]])) * gar[a[pos[len - 1]] - 1];
tsum += ans[i];
len--;
}
}
for (int i = 1; i <= n; i++) {
printf("%I64d\n", ans[i]);
}
return 0;
}
| a.cc: In function 'int main()':
a.cc:47:25: error: 'i' was not declared in this scope
47 | printf("%I64d\n", a[i]);
| ^
|
s023507848 | p03801 | Java | import java.util.Arrays;
import java.util.Scanner;
public class MainE {
MyScanner sc = new MyScanner();
Scanner sc2 = new Scanner(System.in);
long start = System.currentTimeMillis();
long fin = System.currentTimeMillis();
final int MOD = 1000000007;
int[] dx = { 1, 0, 0, -1 };
int[] dy = { 0, 1, -1, 0 };
void run() {
int n = sc.nextInt();
Pair[] p = new Pair[n + 1];
for (int i = 0; i < n; i++)
p[i] = new Pair(i + 1, sc.nextLong());
p[n] = new Pair(0, 0);
Arrays.sort(p);
for (int i = 0; i <= n; i++) {
//p[i].show();
}
long[] res = new long[n + 1];
long cnt = 0;
for (int i = 0; i < n; i++) {
Pair nowP = p[i];
int now = i;
cnt++;
while (nowP.cnt == p[i + 1].cnt) {
i++;
cnt++;
}
// System.out.println( "next = " + (i + 1) + " diff = " + (i - now + 1) + " diffV = " + (nowP.cnt - p[i + 1].cnt));
// System.out.println("cnt = " + cnt);
res[nowP.id] = cnt * (nowP.cnt - p[i+1].cnt);
}
for (int i =1 ; i < n + 1; i++) {
System.out.println(res[i]);
}
}
class Pair implements Comparable<Pair> {
int id;
long cnt;
public Pair() {
super();
this.id = 0;
this.cnt = 0;
}
public Pair(int id, long cnt) {
super();
this.id = id;
this.cnt = cnt;
}
@Override
public int compareTo(Pair arg0) {
if (this.cnt == arg0.cnt) {
return this.id - arg0.id;
}
return -Long.compare(this.cnt, arg0.cnt);
}
void show() {
System.out.println("id = " + this.id + " cnt = " + this.cnt);
}
}
public static void main(String[] args) {
new MainE().run();
}
void debug(Object... o) {
System.out.println(Arrays.deepToString(o));
}
void debug2(int[][] array) {
for (int i = 0; i < array.length; i++) {
for (int j = 0; j < array[i].length; j++) {
System.out.print(array[i][j]);
}
System.out.println();
}
}
boolean inner(int h, int w, int limH, int limW) {
return 0 <= h && h < limH && 0 <= w && w < limW;
}
void swap(int[] x, int a, int b) {
int tmp = x[a];
x[a] = x[b];
x[b] = tmp;
}
// find minimum i (k <= a[i])
int lower_bound(int a[], int k) {
int l = -1;
int r = a.length;
while (r - l > 1) {
int mid = (l + r) / 2;
if (k <= a[mid])
r = mid;
else
l = mid;
}
// r = l + 1
return r;
}
// find minimum i (k < a[i])
int upper_bound(int a[], int k) {
int l = -1;
int r = a.length;
while (r - l > 1) {
int mid = (l + r) / 2;
if (k < a[mid])
r = mid;
else
l = mid;
}
// r = l + 1
return r;
}
int gcd(int a, int b) {
return a % b == 0 ? b : gcd(b, a % b);
}
int lcm(int a, int b) {
return a * b / gcd(a, b);
}
boolean palindrome(String s) {
for (int i = 0; i < s.length() / 2; i++) {
if (s.charAt(i) != s.charAt(s.length() - 1 - i)) {
return false;
}
}
return true;
}
class MyScanner {
int nextInt() {
try {
int c = System.in.read();
while (c != '-' && (c < '0' || '9' < c))
c = System.in.read();
if (c == '-')
return -nextInt();
int res = 0;
do {
res *= 10;
res += c - '0';
c = System.in.read();
} while ('0' <= c && c <= '9');
return res;
} catch (Exception e) {
return -1;
}
}
double nextDouble() {
return Double.parseDouble(next());
}
long nextLong() {
return Long.parseLong(next());
}
String next() {
try {
StringBuilder res = new StringBuilder("");
int c = System.in.read();
while (Character.isWhitespace(c))
c = System.in.read();
do {
res.append((char) c);
} while (!Character.isWhitespace(c = System.in.read()));
return res.toString();
} catch (Exception e) {
return null;
}
}
int[] nextIntArray(int n) {
int[] in = new int[n];
for (int i = 0; i < n; i++) {
in[i] = nextInt();
}
return in;
}
int[][] nextInt2dArray(int n, int m) {
int[][] in = new int[n][m];
for (int i = 0; i < n; i++) {
in[i] = nextIntArray(m);
}
return in;
}
double[] nextDoubleArray(int n) {
double[] in = new double[n];
for (int i = 0; i < n; i++) {
in[i] = nextDouble();
}
return in;
}
long[] nextLongArray(int n) {
long[] in = new long[n];
for (int i = 0; i < n; i++) {
in[i] = nextLong();
}
return in;
}
char[][] nextCharField(int n, int m) {
char[][] in = new char[n][m];
for (int i = 0; i < n; i++) {
String s = sc.next();
for (int j = 0; j < m; j++) {
in[i][j] = s.charAt(j);
}
}
return in;
}
}
} | Main.java:4: error: class MainE is public, should be declared in a file named MainE.java
public class MainE {
^
1 error
|
s739770186 | p03801 | Java | import java.util.*;
class Main {
static int N;
static int[] a;
static long[][] is;
static long[] freq;
static long[] cum;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
N = sc.nextInt();
a = new int[N];
is = new long[2][N];
freq = new long[N + 1];
cum = new long[N];
Arrays.fill(is[0], -1);
Arrays.fill(is[1], -1);
Arrays.fill(freq, -1);
for (int i = 0; i < N; ++i) {
a[i] = sc.nextInt();
}
int p = 0;
for (int i = 0; i < N; ++i) {
if (i == 0 || is[0][p - 1] < a[i]) {
is[0][p] = a[i];
is[1][p] = i + 1;
++p;
}
}
is[0] = Arrays.copyOf(is[0], p);
is[1] = Arrays.copyOf(is[1], p);
Arrays.sort(a);
for (int i = 0; i < N; ++i) {
cum[i] = (i > 0 ? cum[i - 1] : 0) + a[i];
}
for (int i = p - 1; i >= 1; --i) {
int t = binarySearch(a, is[0][i]);
int s = binarySearch(a, is[0][i - 1]);
freq[is[1][i]] = cum[t - 1] - cum[s] - (t - s - 1) * is[0][i - 1] + (N - t) * (is[0][i] - is[0][i - 1]);
}
int t = binarySearch(a, is[0][0]);
freq[is[1][0]] = (t > 0 ? cum[t - 1] : 0) + (N - t) * is[0][0];
for (int i = 1; i <= N; ++i) {
System.out.println(Math.max(freq[i], 0));
}
}
// 同じ数字が続いているときは一番後ろを返す。
static int binarySearch(int[] a, int key) {
int s = -1;
int t = a.length;
while (t - s > 1) {
int m = (s + t) / 2;
if (a[m] > key) {
t = m;
} else {
s = m;
}
}
if (a[s] != key)
s *= -1;
return s;
}
static void tr(Object... objects) {
System.out.println(Arrays.deepToString(objects));
}
} | Main.java:39: error: incompatible types: possible lossy conversion from long to int
int t = binarySearch(a, is[0][i]);
^
Main.java:40: error: incompatible types: possible lossy conversion from long to int
int s = binarySearch(a, is[0][i - 1]);
^
Main.java:41: error: incompatible types: possible lossy conversion from long to int
freq[is[1][i]] = cum[t - 1] - cum[s] - (t - s - 1) * is[0][i - 1] + (N - t) * (is[0][i] - is[0][i - 1]);
^
Main.java:43: error: incompatible types: possible lossy conversion from long to int
int t = binarySearch(a, is[0][0]);
^
Main.java:44: error: incompatible types: possible lossy conversion from long to int
freq[is[1][0]] = (t > 0 ? cum[t - 1] : 0) + (N - t) * is[0][0];
^
Note: Some messages have been simplified; recompile with -Xdiags:verbose to get full output
5 errors
|
s814717904 | p03801 | C++ | #include <iostream>
#include <vector>
#include <queue>
#include <functional>
#include <set>
#include <cmath>
#include <map>
using namespace std;
typedef pair<long long int, long long int> P;
int main() {
long long int n;
cin >> n;
vector<long long int> a(n, 0);
vector<long long int> b(n, 0);
set<long long int> st;
map<long long int, long long int> mp;
vector<P> v;
for (long long int i = 0; i < n; i++) {
cin >> a[i];
mp[a[i]]++;
if (st.find(a[i]) == st.end()) {
v.push_back(P(a[i], i));
st.insert(a[i]);
//mp[a[i]]++;
}
}
sort(v.begin(), v.end(), greater<P>());
//cout << v[0].first << ' ' << v[0].second << endl;
for (long long int i = 0; i+1 < v.size(); i++) {
b[v[i].second] = (v[i].first-v[i+1].first)*mp[v[i].first];
v[i+1].second = min(v[i+1].second, v[i].second);
mp[v[i+1].first] += mp[v[i].first];
//cout << v[i].first << ' ' << mp[v[i].first] << endl;
}
b[0] = n;
for (long long int i = 0; i < n; i++) {
cout << b[i] << endl;
}
return 0;
} | a.cc: In function 'int main()':
a.cc:30:9: error: 'sort' was not declared in this scope; did you mean 'sqrt'?
30 | sort(v.begin(), v.end(), greater<P>());
| ^~~~
| sqrt
|
s865771079 | p03801 | C | #include<stdio.h>
long long sum[100000];
typedef struct{
long long a;
long id;
} stone;
stone a[100000];
int cmp(const void *a, const void *b){
if(((stone*)a)->a==((stone)*b)->a){
return ((stone*)a)->id-((stone)*b)->id;
}
return ((stone*)a)->b-((stone)*b)->a;
}
int main(int argc, char const *argv[]) {
long n,i;
long long max,c;
scanf("%ld",&n);
for(i=0;i<n;i++){
scanf("%lld",&a[i].a);
a[i].id=i;
}
qsort(a,n,sizeof(stone),cmp);
max=a[0].a;
c=0
for(i=0;i<n;i++){
if(max==a[i].a) c++;
else{
s[a[0].id]+=c*(max-a[i].id);
if(a[0].id>a[i].id) a[0].id=a[i].id;
max=a[i].a;
c=1;
}
}
s[a[0].id]+=c*max;
for(i=0;i<n;i++){
printf("%lld\n",s[i]);
}
return 0;
} | main.c: In function 'cmp':
main.c:12:36: warning: dereferencing 'void *' pointer
12 | if(((stone*)a)->a==((stone)*b)->a){
| ^~
main.c:12:29: error: invalid use of void expression
12 | if(((stone*)a)->a==((stone)*b)->a){
| ^
main.c:13:48: warning: dereferencing 'void *' pointer
13 | return ((stone*)a)->id-((stone)*b)->id;
| ^~
main.c:13:41: error: invalid use of void expression
13 | return ((stone*)a)->id-((stone)*b)->id;
| ^
main.c:15:27: error: 'stone' has no member named 'b'
15 | return ((stone*)a)->b-((stone)*b)->a;
| ^~
main.c:15:39: warning: dereferencing 'void *' pointer
15 | return ((stone*)a)->b-((stone)*b)->a;
| ^~
main.c:15:32: error: invalid use of void expression
15 | return ((stone*)a)->b-((stone)*b)->a;
| ^
main.c: In function 'main':
main.c:26:9: error: implicit declaration of function 'qsort' [-Wimplicit-function-declaration]
26 | qsort(a,n,sizeof(stone),cmp);
| ^~~~~
main.c:28:12: error: expected ';' before 'for'
28 | c=0
| ^
| ;
29 | for(i=0;i<n;i++){
| ~~~
main.c:40:33: error: 's' undeclared (first use in this function)
40 | printf("%lld\n",s[i]);
| ^
main.c:40:33: note: each undeclared identifier is reported only once for each function it appears in
|
s821779128 | p03801 | C++ | #include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <string.h>
#define MAX_N 100005
#define MAX_BIT 1000000000
long long max[MAX_N];
long long num[MAX_N];
long long nowMax;
long long solve(void);
int bit[MAX_BIT];
void addRange(long long l,long long r);
void add(long long a, int w);
long long sum(long long a);
long long n;
int main(int argc, const char * argv[]) {
scanf("%lld",&n);
nowMax = 0;
memset(bit,0,sizeof(bit));
for(int i=0;i<n;i++){
long long k;
scanf("%lld",&k);
num[i]=k;
max[i] = nowMax;
if(nowMax < k){
nowMax = k;
}
addRange(1,k);
}
for(int i=0;i<n;i++){
if(num[i] > max[i])
printf("%lld\n",(num[i]-max[i]) * sum(num[i]));
else
printf("0\n");
}
return 0;
}
void addRange(long long l,long long r){//Add 1 to the range (l,r] : l exclusive r inclusive
add(l,1);
add(r+1,-1);
}
void add(long long a, int w){
for(long long x=a;x<=n;x+=x&-x)
bit[x] += w;
}
long long sum(long long a){
long long ret=0;
for(long long x=a;x>0; x-=x&-x){
ret += bit[x];
}
return ret;
} | /tmp/ccjbqK8e.o: in function `main':
a.cc:(.text+0x13): relocation truncated to fit: R_X86_64_PC32 against symbol `n' defined in .bss section in /tmp/ccjbqK8e.o
a.cc:(.text+0xf2): relocation truncated to fit: R_X86_64_PC32 against symbol `n' defined in .bss section in /tmp/ccjbqK8e.o
a.cc:(.text+0x1cf): relocation truncated to fit: R_X86_64_PC32 against symbol `n' defined in .bss section in /tmp/ccjbqK8e.o
/tmp/ccjbqK8e.o: in function `add(long long, int)':
a.cc:(.text+0x279): relocation truncated to fit: R_X86_64_PC32 against symbol `n' defined in .bss section in /tmp/ccjbqK8e.o
collect2: error: ld returned 1 exit status
|
s264643379 | p03801 | C++ | #define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define rep2(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,n) for(int i=(n)-1;i>=0;--i)
#define rrep2(i,a,b) for(int i=(a)-1;i>=b;--i)
// #define range(i,a,b,c) for(int i=a;\
c>0?i<b:\
i>b;\
i+=c)
#define chmax(a, b) (a = (a) < (b) ? (b) : (a))
#define chmin(a, b) (a = (a) > (b) ? (b) : (a))
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define all(a) begin(a),end(a)
#define ifnot(a) if(not (a))
#define dump(x) cerr << #x << " = " << (x) << endl
// #define int ll
#ifdef _MSC_VER
const bool test = true;
#else
const bool test = false;
#endif
int dx[] = { 1,0,-1,0 };
int dy[] = { 0,1,0,-1 };
const int INF = 1 << 28;
const ll INFL = (ll)1 << 58;
ll mod = (int)1e9 + 7;
const double eps = 1e-10;
typedef long double Real;
// return -1, 0, 1
int sgn(const Real& r) { return (r > eps) - (r < -eps); }
int sgn(const Real& a, const Real &b) { return sgn(a - b); }
//.....................
const int MAX = (int)2e5 + 5;
vector<string> split(const string &str, char sep) {
vector<string> v;
stringstream ss(str);
string buffer;
while (getline(ss, buffer, sep)) {
v.push_back(buffer);
}
return v;
}
int H, W;
bool ng(int y, int x) {
return y < 0 || H <= y || x < 0 || W <= x;
}
// segment tree of min
struct RMQ {
int n;
ll d[262244]; // caution : 2^x
void init(int nmin) {
for (n = 1; n < nmin; n *= 2);
memset(d, INF, 2 * n);
}
void update(int i, ll x) {
d[n + i] = x;
for (int k = (n + i) / 2; k > 0; k >>= 1)
d[k] = min(d[k * 2], d[k * 2 + 1]);
}
int get(int l, int r) const {
ll m = INF;
for (; l && l + (l&-l) <= r; l += l&-l)
m = min(m, d[(n + l) / (l&-l)]);
for (; l < r; r -= r&-r)
m = min(m, d[(n + r) / (r&-r) - 1]);
return m;
}
};
RMQ rmq;
ll n, m;
vector<ll> a;
struct Mountain_priority_num {
int num, id;
bool operator < (const Mountain_priority_num& r) const {
if (num != r.num) return num < r.num;
return id > r.id;
}
};
struct Mountain_priority_id {
int num, id;
bool operator < (const Mountain_priority_id r) const {
}
};
void solve() {
cin >> n;
a.resize(n);
rmq.init(n + 10000);
set<Mountain_priority_num> set1;
map<int, int> res;
rep(i, n) {
cin >> a[i];
rmq.update(i, INFL-a[i]);
set1.insert({a[i], i});
}
while (not set1.empty()) {
auto max_n_mountain = *set1.rbegin();
set1.erase(max_n_mountain);
ll a = rmq.get(0, max_n_mountain.id);
ll b = rmq.get(max_n_mountain.id + 1, n);
ll c = max(a, b);
ll d = max_n_mountain.num - c;
if (a < b) {
// 1
max_n_mountain.num -= d;
rmq.update(max_n_mountain.id, max_n_mountain + d);
res[max_n_mountain.id] += d;
// 2
}
}
}
a
signed main() {
int T = 100;
cout << fixed << setprecision(15);
rep(i, T) {
char s[MAX];
if (scanf("%s", s) == EOF) break;
int n = strlen(s);
for (int i = n - 1; i > -1; i--) {
ungetc(s[i], stdin);
}
solve();
}
return 0;
} | a.cc: In member function 'bool Mountain_priority_id::operator<(Mountain_priority_id) const':
a.cc:99:9: warning: no return statement in function returning non-void [-Wreturn-type]
99 | }
| ^
a.cc: In function 'void solve()':
a.cc:111:28: warning: narrowing conversion of 'a.std::vector<long long int>::operator[](((std::vector<long long int>::size_type)i))' from '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} to 'int' [-Wnarrowing]
111 | set1.insert({a[i], i});
| ~~~~~~~~~~~^~~~~~~~~~~
a.cc:125:70: error: no match for 'operator+' (operand types are 'Mountain_priority_num' and 'll' {aka 'long long int'})
125 | rmq.update(max_n_mountain.id, max_n_mountain + d);
| ~~~~~~~~~~~~~~ ^ ~
| | |
| | ll {aka long long int}
| Mountain_priority_num
In file included from /usr/include/c++/14/bits/stl_algobase.h:67,
from /usr/include/c++/14/algorithm:60,
from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
from a.cc:4:
/usr/include/c++/14/bits/stl_iterator.h:627:5: note: candidate: 'template<class _Iterator> constexpr std::reverse_iterator<_Iterator> std::operator+(typename reverse_iterator<_Iterator>::difference_type, const reverse_iterator<_Iterator>&)'
627 | operator+(typename reverse_iterator<_Iterator>::difference_type __n,
| ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:627:5: note: template argument deduction/substitution failed:
a.cc:125:72: note: mismatched types 'const std::reverse_iterator<_Iterator>' and 'll' {aka 'long long int'}
125 | rmq.update(max_n_mountain.id, max_n_mountain + d);
| ^
/usr/include/c++/14/bits/stl_iterator.h:1798:5: note: candidate: 'template<class _Iterator> constexpr std::move_iterator<_IteratorL> std::operator+(typename move_iterator<_IteratorL>::difference_type, const move_iterator<_IteratorL>&)'
1798 | operator+(typename move_iterator<_Iterator>::difference_type __n,
| ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:1798:5: note: template argument deduction/substitution failed:
a.cc:125:72: note: mismatched types 'const std::move_iterator<_IteratorL>' and 'll' {aka 'long long int'}
125 | rmq.update(max_n_mountain.id, max_n_mountain + d);
| ^
In file included from /usr/include/c++/14/string:54,
from /usr/include/c++/14/bitset:52,
from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52:
/usr/include/c++/14/bits/basic_string.h:3598:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(const __cxx11::basic_string<_CharT, _Traits, _Allocator>&, const __cxx11::basic_string<_CharT, _Traits, _Allocator>&)'
3598 | operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
| ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3598:5: note: template argument deduction/substitution failed:
a.cc:125:72: note: 'Mountain_priority_num' is not derived from 'const std::__cxx11::basic_string<_CharT, _Traits, _Allocator>'
125 | rmq.update(max_n_mountain.id, max_n_mountain + d);
| ^
/usr/include/c++/14/bits/basic_string.h:3616:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(const _CharT*, const __cxx11::basic_string<_CharT, _Traits, _Allocator>&)'
3616 | operator+(const _CharT* __lhs,
| ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3616:5: note: template argument deduction/substitution failed:
a.cc:125:72: note: mismatched types 'const _CharT*' and 'Mountain_priority_num'
125 | rmq.update(max_n_mountain.id, max_n_mountain + d);
| ^
/usr/include/c++/14/bits/basic_string.h:3635:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(_CharT, const __cxx11::basic_string<_CharT, _Traits, _Allocator>&)'
3635 | operator+(_CharT __lhs, const basic_string<_CharT,_Traits,_Alloc>& __rhs)
| ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3635:5: note: template argument deduction/substitution failed:
a.cc:125:72: note: mismatched types 'const std::__cxx11::basic_string<_CharT, _Traits, _Allocator>' and 'll' {aka 'long long int'}
125 | rmq.update(max_n_mountain.id, max_n_mountain + d);
| ^
/usr/include/c++/14/bits/basic_string.h:3652:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(const __cxx11::basic_string<_CharT, _Traits, _Allocator>&, const _CharT*)'
3652 | operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
| ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3652:5: note: template argument deduction/substitution failed:
a.cc:125:72: note: 'Mountain_priority_num' is not derived from 'const std::__cxx11::basic_string<_CharT, _Traits, _Allocator>'
125 | rmq.update(max_n_mountain.id, max_n_mountain + d);
| ^
/usr/include/c++/14/bits/basic_string.h:3670:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(const __cxx11::basic_string<_CharT, _Traits, _Allocator>&, _CharT)'
3670 | operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs, _CharT __rhs)
| ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3670:5: note: template argument deduction/substitution failed:
a.cc:125:72: note: 'Mountain_priority_num' is not derived from 'const std::__cxx11::basic_string<_CharT, _Traits, _Allocator>'
125 | rmq.update(max_n_mountain.id, max_n_mountain + d);
| ^
/usr/include/c++/14/bits/basic_string.h:3682:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(__cxx11::basic_string<_CharT, _Traits, _Allocator>&&, const __cxx11::basic_string<_CharT, _Traits, _Allocator>&)'
3682 | operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs,
| ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3682:5: note: template argument deduction/substitution failed:
a.cc:125:72: note: 'Mountain_priority_num' is not derived from 'std::__cxx11::basic_string<_CharT, _Traits, _Allocator>'
125 | rmq.update(max_n_mountain.id, max_n_mountain + d);
| ^
/usr/include/c++/14/bits/basic_string.h:3689:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(const __cxx11::basic_string<_CharT, _Traits, _Allocator>&, __cxx11::basic_string<_CharT, _Traits, _Allocator>&&)'
3689 | operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
| ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3689:5: note: template argument deduction/substitution failed:
a.cc:125:72: note: 'Mountain_priority_num' is not derived from 'const std::__cxx11::basic_string<_CharT, _Traits, _Allocator>'
125 | rmq.update(max_n_mountain.id, max_n_mountain + d);
| ^
/usr/include/c++/14/bits/basic_string.h:3696:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(__cxx11::basic_string<_CharT, _Traits, _Allocator>&&, __cxx11::basic_string<_CharT, _Traits, _Allocator>&&)'
3696 | operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs,
| ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3696:5: note: template argument deduction/substitution failed:
a.cc:125:72: note: 'Mountain_priority_num' is not derived from 'std::__cxx11::basic_string<_CharT, _Traits, _Allocator>'
125 | rmq.update(max_n_mountain.id, max_n_mountain + d);
| ^
/usr/include/c++/14/bits/basic_string.h:3719:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(const _CharT*, __cxx11::basic_string<_CharT, _Traits, _Allocator>&&)'
3719 | operator+(const _CharT* __lhs,
| ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3719:5: note: template argument deduction/substitution failed:
a.cc:125:72: note: mismatched types 'const _CharT*' and 'Mountain_priority_num'
125 | rmq.update(max_n_mountain.id, max_n_mountain + d);
| ^
/usr/include/c++/14/bits/basic_string.h:3726:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(_CharT, __cxx11::basic_string<_CharT, _Traits, _Allocator>&&)'
3726 | operator+(_CharT __lhs,
| ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3726:5: note: template argument deduction/substitution failed:
a.cc:125:72: no |
s349751832 | p03801 | C++ | #include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <string.h>
#define MAX_N 100005
#define MAX_BIT 1000000000
long long max[MAX_N];
long long num[MAX_N];
long long nowMax;
long long solve(void);
long long bit[MAX_BIT];
void addRange(long long l,long long r);
void add(long long a, int w);
long long sum(long long a);
long long n;
int main(int argc, const char * argv[]) {
scanf("%lld",&n);
nowMax = 0;
memset(bit,0,sizeof(bit));
for(int i=0;i<n;i++){
long long k;
scanf("%lld",&k);
num[i]=k;
max[i] = nowMax;
if(nowMax < k){
nowMax = k;
}
addRange(1,k);
}
for(int i=0;i<n;i++){
if(num[i] > max[i])
printf("%lld\n",(num[i]-max[i]) * sum(num[i]));
else
printf("0\n");
}
return 0;
}
void addRange(long long l,long long r){//Add 1 to the range (l,r] : l exclusive r inclusive
add(l,1);
add(r+1,-1);
}
void add(long long a, int w){
for(long long x=a;x<=n;x+=x&-x)
bit[x] += w;
}
long long sum(long long a){
long long ret=0;
for(long long x=a;x>0; x-=x&-x){
ret += bit[x];
}
return ret;
} | /tmp/ccson3rM.o: in function `main':
a.cc:(.text+0x13): relocation truncated to fit: R_X86_64_PC32 against symbol `n' defined in .bss section in /tmp/ccson3rM.o
a.cc:(.text+0xf7): relocation truncated to fit: R_X86_64_PC32 against symbol `n' defined in .bss section in /tmp/ccson3rM.o
a.cc:(.text+0x1d4): relocation truncated to fit: R_X86_64_PC32 against symbol `n' defined in .bss section in /tmp/ccson3rM.o
/tmp/ccson3rM.o: in function `add(long long, int)':
a.cc:(.text+0x283): relocation truncated to fit: R_X86_64_PC32 against symbol `n' defined in .bss section in /tmp/ccson3rM.o
collect2: error: ld returned 1 exit status
|
s788798800 | p03801 | C++ | #include<bits/stdc++.h>
#define FOR(i,a,b) for(int i = (a);i<=(b);i++)
#define ROF(i,a,b) for(int i = (a);i>=(b);i--)
#define FR(i,a,b) for(int i = (a);i<(b);i++)
#define RF(i,a,b) for(int i = (a);i>(b);i--)
#define MST(a,x) memset(a,x,sizeof(a))
#define ll long long
#define PB push_back
#define PH push
#define MP make_pair
#define FT first
#define SD second
#define N 100005
#define M 51
#define INF 100000000000000007
#define MOD 1000000007
#define MOD2 1000000009
#define eps 1e-14
using namespace std;
inline int Max(int a,int b)
{
return (((b-a)>>(32-1))&(a^b))^b;
}
inline int Min(int a,int b)
{
return (((b-a)>>(32-1))&(a^b))^a;
}
ll a[N];
ll rmp[N];
pair<ll,int>b[N];
vector<ll>v;
void update(int p,pair<ll,int> x)
{
while(p<N)
{
b[p].FT+=x.FT;
b[p].SD+=x.SD;
p+=p&-p;
}
}
pair<ll,int> query(int p)
{
pair<ll,int> ret = MP(0,0);
while(p>0)
{
ret.FT+=b[p].FT;
ret.SD+=b[p].SD;
p-=p&-p;
}
return ret;
}
int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
v.clear();
FOR(i,1,n)
{
scanf("%I64d",&a[i]);
v.PB(a[i]);
}
sort(v.begin(),v.end());
int sz = unique(v.begin(),v.end())-v.begin();
v.resize(sz);
rmp[0] = 0;
FOR(i,1,n)
{
int p = lower_bound(v.begin(),v.end(),a[i])-v.begin()+1;
rmp[p] = a[i];
update(p,MP(a[i],1));
}
int p1 = 0,p2 = 0;
FOR(i,1,n)
{
int p = lower_bound(v.begin(),v.end(),a[i])-v.begin()+1;
if(p<p2)
{
update(p,MP(-a[i],-1));
printf("0\n");
continue;
}
p1 = p2;
p2 = p;
//cout<<p1<<" "<<p2<<endl;
pair<ll,int> x = query(p1);
pair<ll,int> y = query(p2);
int tot = ;
//cout<<tot<<" ss "<<y.FT<<" "<<y.SD<<" "<<y.FT-y.SD*rmp[p1]<<" "<<tot-y.SD<<" "<<(rmp[p2]-rmp[p1])<<endl;
printf("%I64d\n",y.FT-(y.SD-x.SD)*rmp[p1]-x.FT+(n-i+1-y.SD)*(rmp[p2]-rmp[p1]));
update(p,MP(-a[i],-1));
}
}
return 0;
}
| a.cc: In function 'int main()':
a.cc:89:23: error: expected primary-expression before ';' token
89 | int tot = ;
| ^
|
s467753911 | p03801 | C++ | #include <bits/stdc++.h>
using namespace std;
typedef __int64 LL;
const int maxn = 100000 + 10;
LL t[maxn];
struct point{
int num;
LL x;
bool operator < (const point & rhs) const {
if(x > rhs.x) return true;
else if(x == rhs.x) {
if(num > rhs.num) return true;
else return false;
}
else return false;
}
}p[maxn];
int main() {
int n;
LL a;
scanf("%d", &n);
for(int i = 1; i <= n; i++) {
scanf("%I64d", &a);
p[i].num = i;
p[i].x = a;
}
sort(p + 1, p + n + 1);
for(int i = 1; i <= n; i++) {
if(p[i].x == p[i + 1].x) t[p[i].num] = 0;
else {
t[p[i].num] = (p[i].x - p[i + 1].x) * i;
}
//printf("%d %d\n", p[i].num, p[i].x);
}
for(int i = 1; i <= n; i++) printf("%I64d\n", t[i]);
return 0;
}
| a.cc:5:9: error: '__int64' does not name a type; did you mean '__int64_t'?
5 | typedef __int64 LL;
| ^~~~~~~
| __int64_t
a.cc:7:1: error: 'LL' does not name a type
7 | LL t[maxn];
| ^~
a.cc:11:5: error: 'LL' does not name a type
11 | LL x;
| ^~
a.cc: In member function 'bool point::operator<(const point&) const':
a.cc:13:12: error: 'x' was not declared in this scope
13 | if(x > rhs.x) return true;
| ^
a.cc:13:20: error: 'const struct point' has no member named 'x'
13 | if(x > rhs.x) return true;
| ^
a.cc:14:26: error: 'const struct point' has no member named 'x'
14 | else if(x == rhs.x) {
| ^
a.cc: In function 'int main()':
a.cc:24:5: error: 'LL' was not declared in this scope
24 | LL a;
| ^~
a.cc:27:25: error: 'a' was not declared in this scope
27 | scanf("%I64d", &a);
| ^
a.cc:29:14: error: 'struct point' has no member named 'x'
29 | p[i].x = a;
| ^
a.cc:33:17: error: 'struct point' has no member named 'x'
33 | if(p[i].x == p[i + 1].x) t[p[i].num] = 0;
| ^
a.cc:33:31: error: 'struct point' has no member named 'x'
33 | if(p[i].x == p[i + 1].x) t[p[i].num] = 0;
| ^
a.cc:33:34: error: 't' was not declared in this scope
33 | if(p[i].x == p[i + 1].x) t[p[i].num] = 0;
| ^
a.cc:35:13: error: 't' was not declared in this scope
35 | t[p[i].num] = (p[i].x - p[i + 1].x) * i;
| ^
a.cc:35:33: error: 'struct point' has no member named 'x'
35 | t[p[i].num] = (p[i].x - p[i + 1].x) * i;
| ^
a.cc:35:46: error: 'struct point' has no member named 'x'
35 | t[p[i].num] = (p[i].x - p[i + 1].x) * i;
| ^
a.cc:39:51: error: 't' was not declared in this scope
39 | for(int i = 1; i <= n; i++) printf("%I64d\n", t[i]);
| ^
a.cc: In member function 'bool point::operator<(const point&) const':
a.cc:19:5: warning: control reaches end of non-void function [-Wreturn-type]
19 | }
| ^
|
s834669911 | p03801 | C++ | #include <bits/stdc++.h>
#define fs first
#define sc second
#define mp make_pair
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
const int N = 100009;
ii a[N];
ll t[N];
ll ans[N];
int main () {
int n; scanf ("%d", &n);
for (int i = 1; i <= n; i++) {
scanf ("%d", &a[i].fs);
a[i].sc = i;
}
sort (a + 1, a + n + 1, cmp);
a[n + 1] = mp (0, n + 1);
int now = n + 1;
for (int i = 1; i <= n; i++) {
now = min (now, a[i].sc);
int j = i;
while (j <= n && a[j].fs == a[i].fs) {
j++;
}
i = --j;
ans[now] += (a[i].fs - a[i + 1].fs) * 1LL * i;
}
for (int i = 1; i <= n; i++) {
printf ("%lld\n", ans[i]);
}
}
| a.cc: In function 'int main()':
a.cc:25:33: error: 'cmp' was not declared in this scope; did you mean 'bcmp'?
25 | sort (a + 1, a + n + 1, cmp);
| ^~~
| bcmp
|
s210045066 | p03802 | C++ | #pragma GCC optimize(3)
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define ll long long
#define pb emplace_back
#define mkp make_pair
#define rint register int
#define INF ((1 << 30) - 1)
#define FI(n) FastIO::read(n)
#define FO(n) FastIO::write(n)
#define Pair pair < int, int >
#define mst(a,b) memset(a,b,sizeof(a))
#define foR(i, k, j) for(rint i = (k); i >= (j); i--)
#define For(i, k, j) for(rint i = (k); i <= (j); i++)
#define Foe(i, u) for(rint i = lst[u], v = e[i].v; i; i = e[i].nxt, v = e[i].v)
#define IOS ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define file(s) freopen(s".in", "r", stdin); freopen(s".out", "w", stdout)
#define ull unsigned ll
const int P = 998244353; //
using namespace std;
inline void ckmax(int &a, int b) {a = max(a, b);}
inline void ckmin(int &a, int b) {a = min(a, b);}
inline void mulmod(int &a, int b) {a = 1ll * a * b % P;}
inline void addmod(int &a, int b) {int t = a + b; a = (t >= P ? t - P : t); }
inline int ksm(int a, int b) {int ans=1; for(;b;b>>=1) {if(b&1) ans=1ll*ans*a%P;a=1ll*a*a%P;}return ans;}
inline int inv(int a) {return ksm(a, P-2);}
inline void printarray(int *a, int n) {For(i, 1, n) fprintf(stderr, "%d ", a[i]); fprintf(stderr, "\n");}
namespace FastIO {
const int SIZE=1<<16; char buf[SIZE], obuf[SIZE], str[64]; int bi=SIZE, bn=SIZE, opt;
int read(char *s) {
while (bn) {for (;bi<bn&&buf[bi]<=' ';bi++);if (bi<bn) break; bn=fread(buf,1,SIZE,stdin),bi=0;}
int sn=0;while (bn) {for (;bi<bn&&buf[bi]>' ';bi++) s[sn++]=buf[bi];if (bi<bn) break; bn=fread(buf,1,SIZE,stdin),bi=0;}s[sn]=0;return sn;
}
bool read(int& x) {if(x)x=0;int bf=0,n=read(str); if(!n) return 0; int i=0; if (str[i]=='-') bf=1,i=1; for(x=0;i<n;i++) x=x*10+str[i]-'0'; if(bf) x=-x; return 1;}
void write(int x) {
if(!x) obuf[opt++] = '0'; else {if(x<0) obuf[opt++]='-',x=-x;int sn=0; while(x)str[sn++]=x%10+'0',x/=10;for (int i=sn-1;i>=0;i--) obuf[opt++]=str[i];}
if (opt>=(SIZE>>1)){fwrite(obuf, 1, opt, stdout); opt=0;}
}
void write(char x) {obuf[opt++]=x;if (opt>=(SIZE>>1)){fwrite(obuf, 1, opt, stdout); opt=0;}}
void Fflush() { if (opt) fwrite(obuf, 1, opt, stdout); opt=0;}
};
const int MAXN = 2e4 + 5;
const int N = MAXN * 13;
int n, ano[MAXN], pos[MAXN][2];
Pair a[MAXN];
#define ls (k << 1)
#define rs (k << 1 | 1)
#define mid ((l + r) >> 1)
vector < int > e[N];
void build(int k, int l, int r) {
if(l == r) return e[k + 2 * n].pb(ano[l]);
e[k + 2 * n].pb(ls + 2 * n), e[k + 2 * n].pb(rs + 2 * n); build(ls, l, mid); build(rs, mid+1, r);
}
void add(int k, int l, int r, int id, int ql, int qr) {
if(ql > qr) return;
if(l == ql && r == qr) return e[id].pb(k + 2 * n);
if(qr <= mid) add(ls, l, mid, id, ql, qr);
else if(mid < ql) add(rs, mid+1, r, id, ql, qr);
else add(ls, l, mid, id, ql, mid), add(rs, mid+1, r, id, mid+1, qr);
}
#undef mid
int dfn[N], low[N], s[N], top = 0, ins[N], col[N], cnt, ind;
void tarjan(int u) {
dfn[u] = low[u] = ++ind; s[++top] = u, ins[u] = 1;
for(auto v : e[u]) {
if(!dfn[v]) {
tarjan(v); ckmin(low[u], low[v]);
} else if(ins[v]) {
ckmin(low[u], low[v]);
}
}
if(low[u] == dfn[u]) {
++cnt;
while(s[top] != u) ins[s[top]] = 0, col[s[top--]] = cnt;
ins[s[top]] = 0, col[s[top--]] = cnt;
}
}
bool check(int mid) {
// cerr << mid << endl;
ind = 0; cnt = 0; For(i, 1, 12 * n) e[i].clear(), dfn[i] = low[i] = 0; build(1, 1, 2 * n);
For(i, 1, 2 * n) {
int l = lower_bound(a + 1, a + 1 + 2 * n, mkp(a[i].first - mid + 1, -INF)) - a,
r = upper_bound(a + 1, a + 1 + 2 * n, mkp(a[i].first + mid - 1, INF)) - a - 1;
int t1 = ano[i], t2 = i; if(t1 > t2) swap(t1, t2);
// if(mid <= 10) cerr << i << ' ' << l << ' ' << r << ' ' << t1 << ' ' << t2 << endl;
add(1, 1, 2 * n, i, l, t1 - 1);
add(1, 1, 2 * n, i, max(l, t1 + 1), min(r, t2 - 1));
add(1, 1, 2 * n, i, t2 + 1, r);
}
For(i, 1, 12 * n) if(!dfn[i]) tarjan(i);
// if(mid <= 10) {
// For(i, 1, 12 * n) cerr << col[i] << ' ';
// cerr << endl;
// For(i, 1, n) cerr << pos[i][0] << ' ' << pos[i][1] << endl;
// cerr << endl << endl;
// }
For(i, 1, n) if(col[pos[i][0]] == col[pos[i][1]]) return 0;
return 1;
}
signed main()
{
#ifndef ONLINE_JUDGE
file("pro");
#endif
FI(n);
For(i, 1, n) {
int x, y; FI(x); FI(y);
a[i*2-1] = mkp(x, i), a[i*2] = mkp(y, i);
}
sort(a + 1, a + 1 + n * 2);
For(i, 1, n * 2) {
if(!pos[a[i].second][0]) pos[a[i].second][0] = i;
else pos[a[i].second][1] = i;
}
// For(i, 1, n) cerr << pos[i][0] << ' ' << pos[i][1] << endl;
// cerr << endl << endl;
For(i, 1, n) ano[pos[i][0]] = pos[i][1], ano[pos[i][1]] = pos[i][0];
int l = 1, r = 1e9, res = -1;
while(l <= r) {
// cerr << l << ' ' << r << endl;
int mid = (l + r) >> 1;
if(check(mid)) {
res = mid, l = mid + 1;
} else r = mid - 1;
}
cout << res << endl;
return FastIO::Fflush(), 0;
}
/*
Think twice :
mod ?
INF ?
n = 1 ?
long long ?
Fastio::Fflush() ?
*/
| a.cc: In function 'void printarray(int*, int)':
a.cc:28:44: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
28 | inline void printarray(int *a, int n) {For(i, 1, n) fprintf(stderr, "%d ", a[i]); fprintf(stderr, "\n");}
| ^
a.cc:14:31: note: in definition of macro 'For'
14 | #define For(i, k, j) for(rint i = (k); i <= (j); i++)
| ^
a.cc: In function 'void build(int, int, int)':
a.cc:52:42: error: return-statement with a value, in function returning 'void' [-fpermissive]
52 | if(l == r) return e[k + 2 * n].pb(ano[l]);
| ~~~~~~~~~~~~~~~^~~~~~~~
a.cc: In function 'void add(int, int, int, int, int, int)':
a.cc:57:47: error: return-statement with a value, in function returning 'void' [-fpermissive]
57 | if(l == ql && r == qr) return e[id].pb(k + 2 * n);
| ~~~~~~~~^~~~~~~~~~~
a.cc: In function 'bool check(int)':
a.cc:81:31: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
81 | ind = 0; cnt = 0; For(i, 1, 12 * n) e[i].clear(), dfn[i] = low[i] = 0; build(1, 1, 2 * n);
| ^
a.cc:14:31: note: in definition of macro 'For'
14 | #define For(i, k, j) for(rint i = (k); i <= (j); i++)
| ^
a.cc:82:13: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
82 | For(i, 1, 2 * n) {
| ^
a.cc:14:31: note: in definition of macro 'For'
14 | #define For(i, k, j) for(rint i = (k); i <= (j); i++)
| ^
a.cc:92:13: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
92 | For(i, 1, 12 * n) if(!dfn[i]) tarjan(i);
| ^
a.cc:14:31: note: in definition of macro 'For'
14 | #define For(i, k, j) for(rint i = (k); i <= (j); i++)
| ^
a.cc:99:13: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
99 | For(i, 1, n) if(col[pos[i][0]] == col[pos[i][1]]) return 0;
| ^
a.cc:14:31: note: in definition of macro 'For'
14 | #define For(i, k, j) for(rint i = (k); i <= (j); i++)
| ^
a.cc: In function 'int main()':
a.cc:108:13: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
108 | For(i, 1, n) {
| ^
a.cc:14:31: note: in definition of macro 'For'
14 | #define For(i, k, j) for(rint i = (k); i <= (j); i++)
| ^
a.cc:113:13: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
113 | For(i, 1, n * 2) {
| ^
a.cc:14:31: note: in definition of macro 'For'
14 | #define For(i, k, j) for(rint i = (k); i <= (j); i++)
| ^
a.cc:119:13: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
119 | For(i, 1, n) ano[pos[i][0]] = pos[i][1], ano[pos[i][1]] = pos[i][0];
| ^
a.cc:14:31: note: in definition of macro 'For'
14 | #define For(i, k, j) for(rint i = (k); i <= (j); i++)
| ^
|
s254631992 | p03802 | C++ | #include <bits/stdc++.h>
#include <stdio.h>
#include <iostream>
#include <cstdio>
#include <bitset>
#include <algorithm>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <string>
#include <string.h>
#include <cmath>
#include <utility>
#include <functional>
#include <map>
#include <set>
#include <cctype>
#include <fstream>
#include <numeric>
#include <cassert>
#include <cstdint>
#include <iomanip>
#include <cstring>
#include <algorithm>
#include <array>
#ifdef _MSC_VER
#include <intrin.h>
#endif
namespace atcoder {
namespace internal {
// @param n `0 <= n`
// @return minimum non-negative `x` s.t. `n <= 2**x`
int ceil_pow2(int n) {
int x = 0;
while ((1U << x) < (unsigned int)(n)) x++;
return x;
}
// @param n `1 <= n`
// @return minimum non-negative `x` s.t. `(n & (1 << x)) != 0`
int bsf(unsigned int n) {
#ifdef _MSC_VER
unsigned long index;
_BitScanForward(&index, n);
return index;
#else
return __builtin_ctz(n);
#endif
}
} // namespace internal
} // namespace atcoder
#include <utility>
namespace atcoder {
namespace internal {
// @param m `1 <= m`
// @return x mod m
constexpr long long safe_mod(long long x, long long m) {
x %= m;
if (x < 0) x += m;
return x;
}
// Fast moduler by barrett reduction
// Reference: https://en.wikipedia.org/wiki/Barrett_reduction
// NOTE: reconsider after Ice Lake
struct barrett {
unsigned int _m;
unsigned long long im;
// @param m `1 <= m`
barrett(unsigned int m) : _m(m), im((unsigned long long)(-1) / m + 1) {}
// @return m
unsigned int umod() const { return _m; }
// @param a `0 <= a < m`
// @param b `0 <= b < m`
// @return `a * b % m`
unsigned int mul(unsigned int a, unsigned int b) const {
// [1] m = 1
// a = b = im = 0, so okay
// [2] m >= 2
// im = ceil(2^64 / m)
// -> im * m = 2^64 + r (0 <= r < m)
// let z = a*b = c*m + d (0 <= c, d < m)
// a*b * im = (c*m + d) * im = c*(im*m) + d*im = c*2^64 + c*r + d*im
// c*r + d*im < m * m + m * im < m * m + 2^64 + m <= 2^64 + m * (m + 1) < 2^64 * 2
// ((ab * im) >> 64) == c or c + 1
unsigned long long z = a;
z *= b;
#ifdef _MSC_VER
unsigned long long x;
_umul128(z, im, &x);
#else
unsigned long long x =
(unsigned long long)(((unsigned __int128)(z)*im) >> 64);
#endif
unsigned int v = (unsigned int)(z - x * _m);
if (_m <= v) v += _m;
return v;
}
};
// @param n `0 <= n`
// @param m `1 <= m`
// @return `(x ** n) % m`
constexpr long long pow_mod_constexpr(long long x, long long n, int m) {
if (m == 1) return 0;
unsigned int _m = (unsigned int)(m);
unsigned long long r = 1;
unsigned long long y = safe_mod(x, m);
while (n) {
if (n & 1) r = (r * y) % _m;
y = (y * y) % _m;
n >>= 1;
}
return r;
}
// Reference:
// M. Forisek and J. Jancina,
// Fast Primality Testing for Integers That Fit into a Machine Word
// @param n `0 <= n`
constexpr bool is_prime_constexpr(int n) {
if (n <= 1) return false;
if (n == 2 || n == 7 || n == 61) return true;
if (n % 2 == 0) return false;
long long d = n - 1;
while (d % 2 == 0) d /= 2;
for (long long a : {2, 7, 61}) {
long long t = d;
long long y = pow_mod_constexpr(a, t, n);
while (t != n - 1 && y != 1 && y != n - 1) {
y = y * y % n;
t <<= 1;
}
if (y != n - 1 && t % 2 == 0) {
return false;
}
}
return true;
}
template <int n> constexpr bool is_prime = is_prime_constexpr(n);
// @param b `1 <= b`
// @return pair(g, x) s.t. g = gcd(a, b), xa = g (mod b), 0 <= x < b/g
constexpr std::pair<long long, long long> inv_gcd(long long a, long long b) {
a = safe_mod(a, b);
if (a == 0) return {b, 0};
// Contracts:
// [1] s - m0 * a = 0 (mod b)
// [2] t - m1 * a = 0 (mod b)
// [3] s * |m1| + t * |m0| <= b
long long s = b, t = a;
long long m0 = 0, m1 = 1;
while (t) {
long long u = s / t;
s -= t * u;
m0 -= m1 * u; // |m1 * u| <= |m1| * s <= b
// [3]:
// (s - t * u) * |m1| + t * |m0 - m1 * u|
// <= s * |m1| - t * u * |m1| + t * (|m0| + |m1| * u)
// = s * |m1| + t * |m0| <= b
auto tmp = s;
s = t;
t = tmp;
tmp = m0;
m0 = m1;
m1 = tmp;
}
// by [3]: |m0| <= b/g
// by g != b: |m0| < b/g
if (m0 < 0) m0 += b / s;
return {s, m0};
}
// Compile time primitive root
// @param m must be prime
// @return primitive root (and minimum in now)
constexpr int primitive_root_constexpr(int m) {
if (m == 2) return 1;
if (m == 167772161) return 3;
if (m == 469762049) return 3;
if (m == 754974721) return 11;
if (m == 998244353) return 3;
int divs[20] = {};
divs[0] = 2;
int cnt = 1;
int x = (m - 1) / 2;
while (x % 2 == 0) x /= 2;
for (int i = 3; (long long)(i)*i <= x; i += 2) {
if (x % i == 0) {
divs[cnt++] = i;
while (x % i == 0) {
x /= i;
}
}
}
if (x > 1) {
divs[cnt++] = x;
}
for (int g = 2;; g++) {
bool ok = true;
for (int i = 0; i < cnt; i++) {
if (pow_mod_constexpr(g, (m - 1) / divs[i], m) == 1) {
ok = false;
break;
}
}
if (ok) return g;
}
}
template <int m> constexpr int primitive_root = primitive_root_constexpr(m);
} // namespace internal
} // namespace atcoder
#include <cassert>
#include <numeric>
#include <type_traits>
namespace atcoder {
namespace internal {
#ifndef _MSC_VER
template <class T>
using is_signed_int128 =
typename std::conditional<std::is_same<T, __int128_t>::value ||
std::is_same<T, __int128>::value,
std::true_type,
std::false_type>::type;
template <class T>
using is_unsigned_int128 =
typename std::conditional<std::is_same<T, __uint128_t>::value ||
std::is_same<T, unsigned __int128>::value,
std::true_type,
std::false_type>::type;
template <class T>
using make_unsigned_int128 =
typename std::conditional<std::is_same<T, __int128_t>::value,
__uint128_t,
unsigned __int128>;
template <class T>
using is_integral = typename std::conditional<std::is_integral<T>::value ||
is_signed_int128<T>::value ||
is_unsigned_int128<T>::value,
std::true_type,
std::false_type>::type;
template <class T>
using is_signed_int = typename std::conditional<(is_integral<T>::value &&
std::is_signed<T>::value) ||
is_signed_int128<T>::value,
std::true_type,
std::false_type>::type;
template <class T>
using is_unsigned_int =
typename std::conditional<(is_integral<T>::value &&
std::is_unsigned<T>::value) ||
is_unsigned_int128<T>::value,
std::true_type,
std::false_type>::type;
template <class T>
using to_unsigned = typename std::conditional<
is_signed_int128<T>::value,
make_unsigned_int128<T>,
typename std::conditional<std::is_signed<T>::value,
std::make_unsigned<T>,
std::common_type<T>>::type>::type;
#else
template <class T> using is_integral = typename std::is_integral<T>;
template <class T>
using is_signed_int =
typename std::conditional<is_integral<T>::value && std::is_signed<T>::value,
std::true_type,
std::false_type>::type;
template <class T>
using is_unsigned_int =
typename std::conditional<is_integral<T>::value &&
std::is_unsigned<T>::value,
std::true_type,
std::false_type>::type;
template <class T>
using to_unsigned = typename std::conditional<is_signed_int<T>::value,
std::make_unsigned<T>,
std::common_type<T>>::type;
#endif
template <class T>
using is_signed_int_t = std::enable_if_t<is_signed_int<T>::value>;
template <class T>
using is_unsigned_int_t = std::enable_if_t<is_unsigned_int<T>::value>;
template <class T> using to_unsigned_t = typename to_unsigned<T>::type;
} // namespace internal
} // namespace atcoder
#include <cassert>
#include <numeric>
#include <type_traits>
#ifdef _MSC_VER
#include <intrin.h>
#endif
namespace atcoder {
namespace internal {
struct modint_base {};
struct static_modint_base : modint_base {};
template <class T> using is_modint = std::is_base_of<modint_base, T>;
template <class T> using is_modint_t = std::enable_if_t<is_modint<T>::value>;
} // namespace internal
template <int m, std::enable_if_t<(1 <= m)>* = nullptr>
struct static_modint : internal::static_modint_base {
using mint = static_modint;
public:
static constexpr int mod() { return m; }
static mint raw(int v) {
mint x;
x._v = v;
return x;
}
static_modint() : _v(0) {}
template <class T, internal::is_signed_int_t<T>* = nullptr>
static_modint(T v) {
long long x = (long long)(v % (long long)(umod()));
if (x < 0) x += umod();
_v = (unsigned int)(x);
}
template <class T, internal::is_unsigned_int_t<T>* = nullptr>
static_modint(T v) {
_v = (unsigned int)(v % umod());
}
static_modint(bool v) { _v = ((unsigned int)(v) % umod()); }
unsigned int val() const { return _v; }
mint& operator++() {
_v++;
if (_v == umod()) _v = 0;
return *this;
}
mint& operator--() {
if (_v == 0) _v = umod();
_v--;
return *this;
}
mint operator++(int) {
mint result = *this;
++*this;
return result;
}
mint operator--(int) {
mint result = *this;
--*this;
return result;
}
mint& operator+=(const mint& rhs) {
_v += rhs._v;
if (_v >= umod()) _v -= umod();
return *this;
}
mint& operator-=(const mint& rhs) {
_v -= rhs._v;
if (_v >= umod()) _v += umod();
return *this;
}
mint& operator*=(const mint& rhs) {
unsigned long long z = _v;
z *= rhs._v;
_v = (unsigned int)(z % umod());
return *this;
}
mint& operator/=(const mint& rhs) { return *this = *this * rhs.inv(); }
mint operator+() const { return *this; }
mint operator-() const { return mint() - *this; }
mint pow(long long n) const {
assert(0 <= n);
mint x = *this, r = 1;
while (n) {
if (n & 1) r *= x;
x *= x;
n >>= 1;
}
return r;
}
mint inv() const {
if (prime) {
assert(_v);
return pow(umod() - 2);
} else {
auto eg = internal::inv_gcd(_v, m);
assert(eg.first == 1);
return eg.second;
}
}
friend mint operator+(const mint& lhs, const mint& rhs) {
return mint(lhs) += rhs;
}
friend mint operator-(const mint& lhs, const mint& rhs) {
return mint(lhs) -= rhs;
}
friend mint operator*(const mint& lhs, const mint& rhs) {
return mint(lhs) *= rhs;
}
friend mint operator/(const mint& lhs, const mint& rhs) {
return mint(lhs) /= rhs;
}
friend bool operator==(const mint& lhs, const mint& rhs) {
return lhs._v == rhs._v;
}
friend bool operator!=(const mint& lhs, const mint& rhs) {
return lhs._v != rhs._v;
}
private:
unsigned int _v;
static constexpr unsigned int umod() { return m; }
static constexpr bool prime = internal::is_prime<m>;
};
template <int id> struct dynamic_modint : internal::modint_base {
using mint = dynamic_modint;
public:
static int mod() { return (int)(bt.umod()); }
static void set_mod(int m) {
assert(1 <= m);
bt = internal::barrett(m);
}
static mint raw(int v) {
mint x;
x._v = v;
return x;
}
dynamic_modint() : _v(0) {}
template <class T, internal::is_signed_int_t<T>* = nullptr>
dynamic_modint(T v) {
long long x = (long long)(v % (long long)(mod()));
if (x < 0) x += mod();
_v = (unsigned int)(x);
}
template <class T, internal::is_unsigned_int_t<T>* = nullptr>
dynamic_modint(T v) {
_v = (unsigned int)(v % mod());
}
dynamic_modint(bool v) { _v = ((unsigned int)(v) % mod()); }
unsigned int val() const { return _v; }
mint& operator++() {
_v++;
if (_v == umod()) _v = 0;
return *this;
}
mint& operator--() {
if (_v == 0) _v = umod();
_v--;
return *this;
}
mint operator++(int) {
mint result = *this;
++*this;
return result;
}
mint operator--(int) {
mint result = *this;
--*this;
return result;
}
mint& operator+=(const mint& rhs) {
_v += rhs._v;
if (_v >= umod()) _v -= umod();
return *this;
}
mint& operator-=(const mint& rhs) {
_v += mod() - rhs._v;
if (_v >= umod()) _v -= umod();
return *this;
}
mint& operator*=(const mint& rhs) {
_v = bt.mul(_v, rhs._v);
return *this;
}
mint& operator/=(const mint& rhs) { return *this = *this * rhs.inv(); }
mint operator+() const { return *this; }
mint operator-() const { return mint() - *this; }
mint pow(long long n) const {
assert(0 <= n);
mint x = *this, r = 1;
while (n) {
if (n & 1) r *= x;
x *= x;
n >>= 1;
}
return r;
}
mint inv() const {
auto eg = internal::inv_gcd(_v, mod());
assert(eg.first == 1);
return eg.second;
}
friend mint operator+(const mint& lhs, const mint& rhs) {
return mint(lhs) += rhs;
}
friend mint operator-(const mint& lhs, const mint& rhs) {
return mint(lhs) -= rhs;
}
friend mint operator*(const mint& lhs, const mint& rhs) {
return mint(lhs) *= rhs;
}
friend mint operator/(const mint& lhs, const mint& rhs) {
return mint(lhs) /= rhs;
}
friend bool operator==(const mint& lhs, const mint& rhs) {
return lhs._v == rhs._v;
}
friend bool operator!=(const mint& lhs, const mint& rhs) {
return lhs._v != rhs._v;
}
private:
unsigned int _v;
static internal::barrett bt;
static unsigned int umod() { return bt.umod(); }
};
template <int id> internal::barrett dynamic_modint<id>::bt = 998244353;
using modint998244353 = static_modint<998244353>;
using modint1000000007 = static_modint<1000000007>;
using modint = dynamic_modint<-1>;
namespace internal {
template <class T>
using is_static_modint = std::is_base_of<internal::static_modint_base, T>;
template <class T>
using is_static_modint_t = std::enable_if_t<is_static_modint<T>::value>;
template <class> struct is_dynamic_modint : public std::false_type {};
template <int id>
struct is_dynamic_modint<dynamic_modint<id>> : public std::true_type {};
template <class T>
using is_dynamic_modint_t = std::enable_if_t<is_dynamic_modint<T>::value>;
} // namespace internal
} // namespace atcoder
#include <cassert>
#include <type_traits>
#include <vector>
namespace atcoder {
namespace internal {
template <class mint, internal::is_static_modint_t<mint>* = nullptr>
void butterfly(std::vector<mint>& a) {
static constexpr int g = internal::primitive_root<mint::mod()>;
int n = int(a.size());
int h = internal::ceil_pow2(n);
static bool first = true;
static mint sum_e[30]; // sum_e[i] = ies[0] * ... * ies[i - 1] * es[i]
if (first) {
first = false;
mint es[30], ies[30]; // es[i]^(2^(2+i)) == 1
int cnt2 = bsf(mint::mod() - 1);
mint e = mint(g).pow((mint::mod() - 1) >> cnt2), ie = e.inv();
for (int i = cnt2; i >= 2; i--) {
// e^(2^i) == 1
es[i - 2] = e;
ies[i - 2] = ie;
e *= e;
ie *= ie;
}
mint now = 1;
for (int i = 0; i < cnt2 - 2; i++) {
sum_e[i] = es[i] * now;
now *= ies[i];
}
}
for (int ph = 1; ph <= h; ph++) {
int w = 1 << (ph - 1), p = 1 << (h - ph);
mint now = 1;
for (int s = 0; s < w; s++) {
int offset = s << (h - ph + 1);
for (int i = 0; i < p; i++) {
auto l = a[i + offset];
auto r = a[i + offset + p] * now;
a[i + offset] = l + r;
a[i + offset + p] = l - r;
}
now *= sum_e[bsf(~(unsigned int)(s))];
}
}
}
template <class mint, internal::is_static_modint_t<mint>* = nullptr>
void butterfly_inv(std::vector<mint>& a) {
static constexpr int g = internal::primitive_root<mint::mod()>;
int n = int(a.size());
int h = internal::ceil_pow2(n);
static bool first = true;
static mint sum_ie[30]; // sum_ie[i] = es[0] * ... * es[i - 1] * ies[i]
if (first) {
first = false;
mint es[30], ies[30]; // es[i]^(2^(2+i)) == 1
int cnt2 = bsf(mint::mod() - 1);
mint e = mint(g).pow((mint::mod() - 1) >> cnt2), ie = e.inv();
for (int i = cnt2; i >= 2; i--) {
// e^(2^i) == 1
es[i - 2] = e;
ies[i - 2] = ie;
e *= e;
ie *= ie;
}
mint now = 1;
for (int i = 0; i < cnt2 - 2; i++) {
sum_ie[i] = ies[i] * now;
now *= es[i];
}
}
for (int ph = h; ph >= 1; ph--) {
int w = 1 << (ph - 1), p = 1 << (h - ph);
mint inow = 1;
for (int s = 0; s < w; s++) {
int offset = s << (h - ph + 1);
for (int i = 0; i < p; i++) {
auto l = a[i + offset];
auto r = a[i + offset + p];
a[i + offset] = l + r;
a[i + offset + p] =
(unsigned long long)(mint::mod() + l.val() - r.val()) *
inow.val();
}
inow *= sum_ie[bsf(~(unsigned int)(s))];
}
}
}
} // namespace internal
template <class mint, internal::is_static_modint_t<mint>* = nullptr>
std::vector<mint> convolution(std::vector<mint> a, std::vector<mint> b) {
int n = int(a.size()), m = int(b.size());
if (!n || !m) return {};
if (std::min(n, m) <= 60) {
if (n < m) {
std::swap(n, m);
std::swap(a, b);
}
std::vector<mint> ans(n + m - 1);
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
ans[i + j] += a[i] * b[j];
}
}
return ans;
}
int z = 1 << internal::ceil_pow2(n + m - 1);
a.resize(z);
internal::butterfly(a);
b.resize(z);
internal::butterfly(b);
for (int i = 0; i < z; i++) {
a[i] *= b[i];
}
internal::butterfly_inv(a);
a.resize(n + m - 1);
mint iz = mint(z).inv();
for (int i = 0; i < n + m - 1; i++) a[i] *= iz;
return a;
}
template <unsigned int mod = 998244353,
class T,
std::enable_if_t<internal::is_integral<T>::value>* = nullptr>
std::vector<T> convolution(const std::vector<T>& a, const std::vector<T>& b) {
int n = int(a.size()), m = int(b.size());
if (!n || !m) return {};
using mint = static_modint<mod>;
std::vector<mint> a2(n), b2(m);
for (int i = 0; i < n; i++) {
a2[i] = mint(a[i]);
}
for (int i = 0; i < m; i++) {
b2[i] = mint(b[i]);
}
auto c2 = convolution(move(a2), move(b2));
std::vector<T> c(n + m - 1);
for (int i = 0; i < n + m - 1; i++) {
c[i] = c2[i].val();
}
return c;
}
std::vector<long long> convolution_ll(const std::vector<long long>& a,
const std::vector<long long>& b) {
int n = int(a.size()), m = int(b.size());
if (!n || !m) return {};
static constexpr unsigned long long MOD1 = 754974721; // 2^24
static constexpr unsigned long long MOD2 = 167772161; // 2^25
static constexpr unsigned long long MOD3 = 469762049; // 2^26
static constexpr unsigned long long M2M3 = MOD2 * MOD3;
static constexpr unsigned long long M1M3 = MOD1 * MOD3;
static constexpr unsigned long long M1M2 = MOD1 * MOD2;
static constexpr unsigned long long M1M2M3 = MOD1 * MOD2 * MOD3;
static constexpr unsigned long long i1 =
internal::inv_gcd(MOD2 * MOD3, MOD1).second;
static constexpr unsigned long long i2 =
internal::inv_gcd(MOD1 * MOD3, MOD2).second;
static constexpr unsigned long long i3 =
internal::inv_gcd(MOD1 * MOD2, MOD3).second;
auto c1 = convolution<MOD1>(a, b);
auto c2 = convolution<MOD2>(a, b);
auto c3 = convolution<MOD3>(a, b);
std::vector<long long> c(n + m - 1);
for (int i = 0; i < n + m - 1; i++) {
unsigned long long x = 0;
x += (c1[i] * i1) % MOD1 * M2M3;
x += (c2[i] * i2) % MOD2 * M1M3;
x += (c3[i] * i3) % MOD3 * M1M2;
// B = 2^63, -B <= x, r(real value) < B
// (x, x - M, x - 2M, or x - 3M) = r (mod 2B)
// r = c1[i] (mod MOD1)
// focus on MOD1
// r = x, x - M', x - 2M', x - 3M' (M' = M % 2^64) (mod 2B)
// r = x,
// x - M' + (0 or 2B),
// x - 2M' + (0, 2B or 4B),
// x - 3M' + (0, 2B, 4B or 6B) (without mod!)
// (r - x) = 0, (0)
// - M' + (0 or 2B), (1)
// -2M' + (0 or 2B or 4B), (2)
// -3M' + (0 or 2B or 4B or 6B) (3) (mod MOD1)
// we checked that
// ((1) mod MOD1) mod 5 = 2
// ((2) mod MOD1) mod 5 = 3
// ((3) mod MOD1) mod 5 = 4
long long diff =
c1[i] - internal::safe_mod((long long)(x), (long long)(MOD1));
if (diff < 0) diff += MOD1;
static constexpr unsigned long long offset[5] = {
0, 0, M1M2M3, 2 * M1M2M3, 3 * M1M2M3};
x -= offset[diff % 5];
c[i] = x;
}
return c;
}
} // namespace atcoder
#include <algorithm>
#include <cassert>
#include <vector>
namespace atcoder {
// Implement (union by size) + (path compression)
// Reference:
// Zvi Galil and Giuseppe F. Italiano,
// Data structures and algorithms for disjoint set union problems
struct dsu {
public:
dsu() : _n(0) {}
dsu(int n) : _n(n), parent_or_size(n, -1) {}
int merge(int a, int b) {
assert(0 <= a && a < _n);
assert(0 <= b && b < _n);
int x = leader(a), y = leader(b);
if (x == y) return x;
if (-parent_or_size[x] < -parent_or_size[y]) std::swap(x, y);
parent_or_size[x] += parent_or_size[y];
parent_or_size[y] = x;
return x;
}
bool same(int a, int b) {
assert(0 <= a && a < _n);
assert(0 <= b && b < _n);
return leader(a) == leader(b);
}
int leader(int a) {
assert(0 <= a && a < _n);
if (parent_or_size[a] < 0) return a;
return parent_or_size[a] = leader(parent_or_size[a]);
}
int size(int a) {
assert(0 <= a && a < _n);
return -parent_or_size[leader(a)];
}
std::vector<std::vector<int>> groups() {
std::vector<int> leader_buf(_n), group_size(_n);
for (int i = 0; i < _n; i++) {
leader_buf[i] = leader(i);
group_size[leader_buf[i]]++;
}
std::vector<std::vector<int>> result(_n);
for (int i = 0; i < _n; i++) {
result[i].reserve(group_size[i]);
}
for (int i = 0; i < _n; i++) {
result[leader_buf[i]].push_back(i);
}
result.erase(
std::remove_if(result.begin(), result.end(),
[&](const std::vector<int>& v) { return v.empty(); }),
result.end());
return result;
}
private:
int _n;
// root node: -1 * component size
// otherwise: parent
std::vector<int> parent_or_size;
};
} // namespace atcoder
#include <cassert>
#include <vector>
namespace atcoder {
// Reference: https://en.wikipedia.org/wiki/Fenwick_tree
template <class T> struct fenwick_tree {
using U = internal::to_unsigned_t<T>;
public:
fenwick_tree() : _n(0) {}
fenwick_tree(int n) : _n(n), data(n) {}
void add(int p, T x) {
assert(0 <= p && p < _n);
p++;
while (p <= _n) {
data[p - 1] += U(x);
p += p & -p;
}
}
T sum(int l, int r) {
assert(0 <= l && l <= r && r <= _n);
return sum(r) - sum(l);
}
private:
int _n;
std::vector<U> data;
U sum(int r) {
U s = 0;
while (r > 0) {
s += data[r - 1];
r -= r & -r;
}
return s;
}
};
} // namespace atcoder
#include <algorithm>
#include <cassert>
#include <iostream>
#include <vector>
namespace atcoder {
template <class S,
S (*op)(S, S),
S (*e)(),
class F,
S (*mapping)(F, S),
F (*composition)(F, F),
F (*id)()>
struct lazy_segtree {
public:
lazy_segtree() : lazy_segtree(0) {}
lazy_segtree(int n) : lazy_segtree(std::vector<S>(n, e())) {}
lazy_segtree(const std::vector<S>& v) : _n(int(v.size())) {
log = internal::ceil_pow2(_n);
size = 1 << log;
d = std::vector<S>(2 * size, e());
lz = std::vector<F>(size, id());
for (int i = 0; i < _n; i++) d[size + i] = v[i];
for (int i = size - 1; i >= 1; i--) {
update(i);
}
}
void set(int p, S x) {
assert(0 <= p && p < _n);
p += size;
for (int i = log; i >= 1; i--) push(p >> i);
d[p] = x;
for (int i = 1; i <= log; i++) update(p >> i);
}
S get(int p) {
assert(0 <= p && p < _n);
p += size;
for (int i = log; i >= 1; i--) push(p >> i);
return d[p];
}
S prod(int l, int r) {
assert(0 <= l && l <= r && r <= _n);
if (l == r) return e();
l += size;
r += size;
for (int i = log; i >= 1; i--) {
if (((l >> i) << i) != l) push(l >> i);
if (((r >> i) << i) != r) push(r >> i);
}
S sml = e(), smr = e();
while (l < r) {
if (l & 1) sml = op(sml, d[l++]);
if (r & 1) smr = op(d[--r], smr);
l >>= 1;
r >>= 1;
}
return op(sml, smr);
}
S all_prod() { return d[1]; }
void apply(int p, F f) {
assert(0 <= p && p < _n);
p += size;
for (int i = log; i >= 1; i--) push(p >> i);
d[p] = mapping(f, d[p]);
for (int i = 1; i <= log; i++) update(p >> i);
}
void apply(int l, int r, F f) {
assert(0 <= l && l <= r && r <= _n);
if (l == r) return;
l += size;
r += size;
for (int i = log; i >= 1; i--) {
if (((l >> i) << i) != l) push(l >> i);
if (((r >> i) << i) != r) push((r - 1) >> i);
}
{
int l2 = l, r2 = r;
while (l < r) {
if (l & 1) all_apply(l++, f);
if (r & 1) all_apply(--r, f);
l >>= 1;
r >>= 1;
}
l = l2;
r = r2;
}
for (int i = 1; i <= log; i++) {
if (((l >> i) << i) != l) update(l >> i);
if (((r >> i) << i) != r) update((r - 1) >> i);
}
}
template <bool (*g)(S)> int max_right(int l) {
return max_right(l, [](S x) { return g(x); });
}
template <class G> int max_right(int l, G g) {
assert(0 <= l && l <= _n);
assert(g(e()));
if (l == _n) return _n;
l += size;
for (int i = log; i >= 1; i--) push(l >> i);
S sm = e();
do {
while (l % 2 == 0) l >>= 1;
if (!g(op(sm, d[l]))) {
while (l < size) {
push(l);
l = (2 * l);
if (g(op(sm, d[l]))) {
sm = op(sm, d[l]);
l++;
}
}
return l - size;
}
sm = op(sm, d[l]);
l++;
} while ((l & -l) != l);
return _n;
}
template <bool (*g)(S)> int min_left(int r) {
return min_left(r, [](S x) { return g(x); });
}
template <class G> int min_left(int r, G g) {
assert(0 <= r && r <= _n);
assert(g(e()));
if (r == 0) return 0;
r += size;
for (int i = log; i >= 1; i--) push((r - 1) >> i);
S sm = e();
do {
r--;
while (r > 1 && (r % 2)) r >>= 1;
if (!g(op(d[r], sm))) {
while (r < size) {
push(r);
r = (2 * r + 1);
if (g(op(d[r], sm))) {
sm = op(d[r], sm);
r--;
}
}
return r + 1 - size;
}
sm = op(d[r], sm);
} while ((r & -r) != r);
return 0;
}
private:
int _n, size, log;
std::vector<S> d;
std::vector<F> lz;
void update(int k) { d[k] = op(d[2 * k], d[2 * k + 1]); }
void all_apply(int k, F f) {
d[k] = mapping(f, d[k]);
if (k < size) lz[k] = composition(f, lz[k]);
}
void push(int k) {
all_apply(2 * k, lz[k]);
all_apply(2 * k + 1, lz[k]);
lz[k] = id();
}
};
} // namespace atcoder
#include <algorithm>
#include <cassert>
#include <tuple>
#include <vector>
namespace atcoder {
long long pow_mod(long long x, long long n, int m) {
assert(0 <= n && 1 <= m);
if (m == 1) return 0;
internal::barrett bt((unsigned int)(m));
unsigned int r = 1, y = (unsigned int)(internal::safe_mod(x, m));
while (n) {
if (n & 1) r = bt.mul(r, y);
y = bt.mul(y, y);
n >>= 1;
}
return r;
}
long long inv_mod(long long x, long long m) {
assert(1 <= m);
auto z = internal::inv_gcd(x, m);
assert(z.first == 1);
return z.second;
}
// (rem, mod)
std::pair<long long, long long> crt(const std::vector<long long>& r,
const std::vector<long long>& m) {
assert(r.size() == m.size());
int n = int(r.size());
// Contracts: 0 <= r0 < m0
long long r0 = 0, m0 = 1;
for (int i = 0; i < n; i++) {
assert(1 <= m[i]);
long long r1 = internal::safe_mod(r[i], m[i]), m1 = m[i];
if (m0 < m1) {
std::swap(r0, r1);
std::swap(m0, m1);
}
if (m0 % m1 == 0) {
if (r0 % m1 != r1) return {0, 0};
continue;
}
// assume: m0 > m1, lcm(m0, m1) >= 2 * max(m0, m1)
// (r0, m0), (r1, m1) -> (r2, m2 = lcm(m0, m1));
// r2 % m0 = r0
// r2 % m1 = r1
// -> (r0 + x*m0) % m1 = r1
// -> x*u0*g % (u1*g) = (r1 - r0) (u0*g = m0, u1*g = m1)
// -> x = (r1 - r0) / g * inv(u0) (mod u1)
// im = inv(u0) (mod u1) (0 <= im < u1)
long long g, im;
std::tie(g, im) = internal::inv_gcd(m0, m1);
long long u1 = (m1 / g);
// |r1 - r0| < (m0 + m1) <= lcm(m0, m1)
if ((r1 - r0) % g) return {0, 0};
// u1 * u1 <= m1 * m1 / g / g <= m0 * m1 / g = lcm(m0, m1)
long long x = (r1 - r0) / g % u1 * im % u1;
// |r0| + |m0 * x|
// < m0 + m0 * (u1 - 1)
// = m0 + m0 * m1 / g - m0
// = lcm(m0, m1)
r0 += x * m0;
m0 *= u1; // -> lcm(m0, m1)
if (r0 < 0) r0 += m0;
}
return {r0, m0};
}
long long floor_sum(long long n, long long m, long long a, long long b) {
long long ans = 0;
if (a >= m) {
ans += (n - 1) * n * (a / m) / 2;
a %= m;
}
if (b >= m) {
ans += n * (b / m);
b %= m;
}
long long y_max = (a * n + b) / m, x_max = (y_max * m - b);
if (y_max == 0) return ans;
ans += (n - (x_max + a - 1) / a) * y_max;
ans += floor_sum(y_max, a, m, (a - x_max % a) % a);
return ans;
}
} // namespace atcoder
#include <algorithm>
#include <vector>
namespace atcoder {
namespace internal {
template <class T> struct simple_queue {
std::vector<T> payload;
int pos = 0;
void reserve(int n) { payload.reserve(n); }
int size() const { return int(payload.size()) - pos; }
bool empty() const { return pos == int(payload.size()); }
void push(const T& t) { payload.push_back(t); }
T& front() { return payload[pos]; }
void clear() {
payload.clear();
pos = 0;
}
void pop() { pos++; }
};
} // namespace internal
} // namespace atcoder
#include <cassert>
#include <limits>
#include <queue>
#include <vector>
namespace atcoder {
template <class Cap> struct mf_graph {
public:
mf_graph() : _n(0) {}
mf_graph(int n) : _n(n), g(n) {}
int add_edge(int from, int to, Cap cap) {
assert(0 <= from && from < _n);
assert(0 <= to && to < _n);
assert(0 <= cap);
int m = int(pos.size());
pos.push_back({from, int(g[from].size())});
g[from].push_back(_edge{to, int(g[to].size()), cap});
g[to].push_back(_edge{from, int(g[from].size()) - 1, 0});
return m;
}
struct edge {
int from, to;
Cap cap, flow;
};
edge get_edge(int i) {
int m = int(pos.size());
assert(0 <= i && i < m);
auto _e = g[pos[i].first][pos[i].second];
auto _re = g[_e.to][_e.rev];
return edge{pos[i].first, _e.to, _e.cap + _re.cap, _re.cap};
}
std::vector<edge> edges() {
int m = int(pos.size());
std::vector<edge> result;
for (int i = 0; i < m; i++) {
result.push_back(get_edge(i));
}
return result;
}
void change_edge(int i, Cap new_cap, Cap new_flow) {
int m = int(pos.size());
assert(0 <= i && i < m);
assert(0 <= new_flow && new_flow <= new_cap);
auto& _e = g[pos[i].first][pos[i].second];
auto& _re = g[_e.to][_e.rev];
_e.cap = new_cap - new_flow;
_re.cap = new_flow;
}
Cap flow(int s, int t) {
return flow(s, t, std::numeric_limits<Cap>::max());
}
Cap flow(int s, int t, Cap flow_limit) {
assert(0 <= s && s < _n);
assert(0 <= t && t < _n);
std::vector<int> level(_n), iter(_n);
internal::simple_queue<int> que;
auto bfs = [&]() {
std::fill(level.begin(), level.end(), -1);
level[s] = 0;
que.clear();
que.push(s);
while (!que.empty()) {
int v = que.front();
que.pop();
for (auto e : g[v]) {
if (e.cap == 0 || level[e.to] >= 0) continue;
level[e.to] = level[v] + 1;
if (e.to == t) return;
que.push(e.to);
}
}
};
auto dfs = [&](auto self, int v, Cap up) {
if (v == s) return up;
Cap res = 0;
int level_v = level[v];
for (int& i = iter[v]; i < int(g[v].size()); i++) {
_edge& e = g[v][i];
if (level_v <= level[e.to] || g[e.to][e.rev].cap == 0) continue;
Cap d =
self(self, e.to, std::min(up - res, g[e.to][e.rev].cap));
if (d <= 0) continue;
g[v][i].cap += d;
g[e.to][e.rev].cap -= d;
res += d;
if (res == up) break;
}
return res;
};
Cap flow = 0;
while (flow < flow_limit) {
bfs();
if (level[t] == -1) break;
std::fill(iter.begin(), iter.end(), 0);
while (flow < flow_limit) {
Cap f = dfs(dfs, t, flow_limit - flow);
if (!f) break;
flow += f;
}
}
return flow;
}
std::vector<bool> min_cut(int s) {
std::vector<bool> visited(_n);
internal::simple_queue<int> que;
que.push(s);
while (!que.empty()) {
int p = que.front();
que.pop();
visited[p] = true;
for (auto e : g[p]) {
if (e.cap && !visited[e.to]) {
visited[e.to] = true;
que.push(e.to);
}
}
}
return visited;
}
private:
int _n;
struct _edge {
int to, rev;
Cap cap;
};
std::vector<std::pair<int, int>> pos;
std::vector<std::vector<_edge>> g;
};
} // namespace atcoder
#include <algorithm>
#include <cassert>
#include <limits>
#include <queue>
#include <vector>
namespace atcoder {
template <class Cap, class Cost> struct mcf_graph {
public:
mcf_graph() {}
mcf_graph(int n) : _n(n), g(n) {}
int add_edge(int from, int to, Cap cap, Cost cost) {
assert(0 <= from && from < _n);
assert(0 <= to && to < _n);
int m = int(pos.size());
pos.push_back({from, int(g[from].size())});
g[from].push_back(_edge{to, int(g[to].size()), cap, cost});
g[to].push_back(_edge{from, int(g[from].size()) - 1, 0, -cost});
return m;
}
struct edge {
int from, to;
Cap cap, flow;
Cost cost;
};
edge get_edge(int i) {
int m = int(pos.size());
assert(0 <= i && i < m);
auto _e = g[pos[i].first][pos[i].second];
auto _re = g[_e.to][_e.rev];
return edge{
pos[i].first, _e.to, _e.cap + _re.cap, _re.cap, _e.cost,
};
}
std::vector<edge> edges() {
int m = int(pos.size());
std::vector<edge> result(m);
for (int i = 0; i < m; i++) {
result[i] = get_edge(i);
}
return result;
}
std::pair<Cap, Cost> flow(int s, int t) {
return flow(s, t, std::numeric_limits<Cap>::max());
}
std::pair<Cap, Cost> flow(int s, int t, Cap flow_limit) {
return slope(s, t, flow_limit).back();
}
std::vector<std::pair<Cap, Cost>> slope(int s, int t) {
return slope(s, t, std::numeric_limits<Cap>::max());
}
std::vector<std::pair<Cap, Cost>> slope(int s, int t, Cap flow_limit) {
assert(0 <= s && s < _n);
assert(0 <= t && t < _n);
assert(s != t);
// variants (C = maxcost):
// -(n-1)C <= dual[s] <= dual[i] <= dual[t] = 0
// reduced cost (= e.cost + dual[e.from] - dual[e.to]) >= 0 for all edge
std::vector<Cost> dual(_n, 0), dist(_n);
std::vector<int> pv(_n), pe(_n);
std::vector<bool> vis(_n);
auto dual_ref = [&]() {
std::fill(dist.begin(), dist.end(),
std::numeric_limits<Cost>::max());
std::fill(pv.begin(), pv.end(), -1);
std::fill(pe.begin(), pe.end(), -1);
std::fill(vis.begin(), vis.end(), false);
struct Q {
Cost key;
int to;
bool operator<(Q r) const { return key > r.key; }
};
std::priority_queue<Q> que;
dist[s] = 0;
que.push(Q{0, s});
while (!que.empty()) {
int v = que.top().to;
que.pop();
if (vis[v]) continue;
vis[v] = true;
if (v == t) break;
// dist[v] = shortest(s, v) + dual[s] - dual[v]
// dist[v] >= 0 (all reduced cost are positive)
// dist[v] <= (n-1)C
for (int i = 0; i < int(g[v].size()); i++) {
auto e = g[v][i];
if (vis[e.to] || !e.cap) continue;
// |-dual[e.to] + dual[v]| <= (n-1)C
// cost <= C - -(n-1)C + 0 = nC
Cost cost = e.cost - dual[e.to] + dual[v];
if (dist[e.to] - dist[v] > cost) {
dist[e.to] = dist[v] + cost;
pv[e.to] = v;
pe[e.to] = i;
que.push(Q{dist[e.to], e.to});
}
}
}
if (!vis[t]) {
return false;
}
for (int v = 0; v < _n; v++) {
if (!vis[v]) continue;
// dual[v] = dual[v] - dist[t] + dist[v]
// = dual[v] - (shortest(s, t) + dual[s] - dual[t]) + (shortest(s, v) + dual[s] - dual[v])
// = - shortest(s, t) + dual[t] + shortest(s, v)
// = shortest(s, v) - shortest(s, t) >= 0 - (n-1)C
dual[v] -= dist[t] - dist[v];
}
return true;
};
Cap flow = 0;
Cost cost = 0, prev_cost = -1;
std::vector<std::pair<Cap, Cost>> result;
result.push_back({flow, cost});
while (flow < flow_limit) {
if (!dual_ref()) break;
Cap c = flow_limit - flow;
for (int v = t; v != s; v = pv[v]) {
c = std::min(c, g[pv[v]][pe[v]].cap);
}
for (int v = t; v != s; v = pv[v]) {
auto& e = g[pv[v]][pe[v]];
e.cap -= c;
g[v][e.rev].cap += c;
}
Cost d = -dual[s];
flow += c;
cost += c * d;
if (prev_cost == d) {
result.pop_back();
}
result.push_back({flow, cost});
prev_cost = cost;
}
return result;
}
private:
int _n;
struct _edge {
int to, rev;
Cap cap;
Cost cost;
};
std::vector<std::pair<int, int>> pos;
std::vector<std::vector<_edge>> g;
};
} // namespace atcoder
#include <algorithm>
#include <algorithm>
#include <utility>
#include <vector>
namespace atcoder {
namespace internal {
template <class E> struct csr {
std::vector<int> start;
std::vector<E> elist;
csr(int n, const std::vector<std::pair<int, E>>& edges)
: start(n + 1), elist(edges.size()) {
for (auto e : edges) {
start[e.first + 1]++;
}
for (int i = 1; i <= n; i++) {
start[i] += start[i - 1];
}
auto counter = start;
for (auto e : edges) {
elist[counter[e.first]++] = e.second;
}
}
};
// Reference:
// R. Tarjan,
// Depth-First Search and Linear Graph Algorithms
struct scc_graph {
public:
scc_graph(int n) : _n(n) {}
int num_vertices() { return _n; }
void add_edge(int from, int to) { edges.push_back({from, {to}}); }
// @return pair of (# of scc, scc id)
std::pair<int, std::vector<int>> scc_ids() {
auto g = csr<edge>(_n, edges);
int now_ord = 0, group_num = 0;
std::vector<int> visited, low(_n), ord(_n, -1), ids(_n);
visited.reserve(_n);
auto dfs = [&](auto self, int v) -> void {
low[v] = ord[v] = now_ord++;
visited.push_back(v);
for (int i = g.start[v]; i < g.start[v + 1]; i++) {
auto to = g.elist[i].to;
if (ord[to] == -1) {
self(self, to);
low[v] = std::min(low[v], low[to]);
} else {
low[v] = std::min(low[v], ord[to]);
}
}
if (low[v] == ord[v]) {
while (true) {
int u = visited.back();
visited.pop_back();
ord[u] = _n;
ids[u] = group_num;
if (u == v) break;
}
group_num++;
}
};
for (int i = 0; i < _n; i++) {
if (ord[i] == -1) dfs(dfs, i);
}
for (auto& x : ids) {
x = group_num - 1 - x;
}
return {group_num, ids};
}
std::vector<std::vector<int>> scc() {
auto ids = scc_ids();
int group_num = ids.first;
std::vector<int> counts(group_num);
for (auto x : ids.second) counts[x]++;
std::vector<std::vector<int>> groups(ids.first);
for (int i = 0; i < group_num; i++) {
groups[i].reserve(counts[i]);
}
for (int i = 0; i < _n; i++) {
groups[ids.second[i]].push_back(i);
}
return groups;
}
private:
int _n;
struct edge {
int to;
};
std::vector<std::pair<int, edge>> edges;
};
} // namespace internal
} // namespace atcoder
#include <cassert>
#include <vector>
namespace atcoder {
struct scc_graph {
public:
scc_graph() : internal(0) {}
scc_graph(int n) : internal(n) {}
void add_edge(int from, int to) {
int n = internal.num_vertices();
assert(0 <= from && from < n);
assert(0 <= to && to < n);
internal.add_edge(from, to);
}
std::vector<std::vector<int>> scc() { return internal.scc(); }
private:
internal::scc_graph internal;
};
} // namespace atcoder
#include <algorithm>
#include <cassert>
#include <vector>
namespace atcoder {
template <class S, S (*op)(S, S), S (*e)()> struct segtree {
public:
segtree() : segtree(0) {}
segtree(int n) : segtree(std::vector<S>(n, e())) {}
segtree(const std::vector<S>& v) : _n(int(v.size())) {
log = internal::ceil_pow2(_n);
size = 1 << log;
d = std::vector<S>(2 * size, e());
for (int i = 0; i < _n; i++) d[size + i] = v[i];
for (int i = size - 1; i >= 1; i--) {
update(i);
}
}
void set(int p, S x) {
assert(0 <= p && p < _n);
p += size;
d[p] = x;
for (int i = 1; i <= log; i++) update(p >> i);
}
S get(int p) {
assert(0 <= p && p < _n);
return d[p + size];
}
S prod(int l, int r) {
assert(0 <= l && l <= r && r <= _n);
S sml = e(), smr = e();
l += size;
r += size;
while (l < r) {
if (l & 1) sml = op(sml, d[l++]);
if (r & 1) smr = op(d[--r], smr);
l >>= 1;
r >>= 1;
}
return op(sml, smr);
}
S all_prod() { return d[1]; }
template <bool (*f)(S)> int max_right(int l) {
return max_right(l, [](S x) { return f(x); });
}
template <class F> int max_right(int l, F f) {
assert(0 <= l && l <= _n);
assert(f(e()));
if (l == _n) return _n;
l += size;
S sm = e();
do {
while (l % 2 == 0) l >>= 1;
if (!f(op(sm, d[l]))) {
while (l < size) {
l = (2 * l);
if (f(op(sm, d[l]))) {
sm = op(sm, d[l]);
l++;
}
}
return l - size;
}
sm = op(sm, d[l]);
l++;
} while ((l & -l) != l);
return _n;
}
template <bool (*f)(S)> int min_left(int r) {
return min_left(r, [](S x) { return f(x); });
}
template <class F> int min_left(int r, F f) {
assert(0 <= r && r <= _n);
assert(f(e()));
if (r == 0) return 0;
r += size;
S sm = e();
do {
r--;
while (r > 1 && (r % 2)) r >>= 1;
if (!f(op(d[r], sm))) {
while (r < size) {
r = (2 * r + 1);
if (f(op(d[r], sm))) {
sm = op(d[r], sm);
r--;
}
}
return r + 1 - size;
}
sm = op(d[r], sm);
} while ((r & -r) != r);
return 0;
}
private:
int _n, size, log;
std::vector<S> d;
void update(int k) { d[k] = op(d[2 * k], d[2 * k + 1]); }
};
} // namespace atcoder
#include <algorithm>
#include <cassert>
#include <numeric>
#include <string>
#include <vector>
namespace atcoder {
namespace internal {
std::vector<int> sa_naive(const std::vector<int>& s) {
int n = int(s.size());
std::vector<int> sa(n);
std::iota(sa.begin(), sa.end(), 0);
std::sort(sa.begin(), sa.end(), [&](int l, int r) {
if (l == r) return false;
while (l < n && r < n) {
if (s[l] != s[r]) return s[l] < s[r];
l++;
r++;
}
return l == n;
});
return sa;
}
std::vector<int> sa_doubling(const std::vector<int>& s) {
int n = int(s.size());
std::vector<int> sa(n), rnk = s, tmp(n);
std::iota(sa.begin(), sa.end(), 0);
for (int k = 1; k < n; k *= 2) {
auto cmp = [&](int x, int y) {
if (rnk[x] != rnk[y]) return rnk[x] < rnk[y];
int rx = x + k < n ? rnk[x + k] : -1;
int ry = y + k < n ? rnk[y + k] : -1;
return rx < ry;
};
std::sort(sa.begin(), sa.end(), cmp);
tmp[sa[0]] = 0;
for (int i = 1; i < n; i++) {
tmp[sa[i]] = tmp[sa[i - 1]] + (cmp(sa[i - 1], sa[i]) ? 1 : 0);
}
std::swap(tmp, rnk);
}
return sa;
}
// SA-IS, linear-time suffix array construction
// Reference:
// G. Nong, S. Zhang, and W. H. Chan,
// Two Efficient Algorithms for Linear Time Suffix Array Construction
template <int THRESHOLD_NAIVE = 10, int THRESHOLD_DOUBLING = 40>
std::vector<int> sa_is(const std::vector<int>& s, int upper) {
int n = int(s.size());
if (n == 0) return {};
if (n == 1) return {0};
if (n == 2) {
if (s[0] < s[1]) {
return {0, 1};
} else {
return {1, 0};
}
}
if (n < THRESHOLD_NAIVE) {
return sa_naive(s);
}
if (n < THRESHOLD_DOUBLING) {
return sa_doubling(s);
}
std::vector<int> sa(n);
std::vector<bool> ls(n);
for (int i = n - 2; i >= 0; i--) {
ls[i] = (s[i] == s[i + 1]) ? ls[i + 1] : (s[i] < s[i + 1]);
}
std::vector<int> sum_l(upper + 1), sum_s(upper + 1);
for (int i = 0; i < n; i++) {
if (!ls[i]) {
sum_s[s[i]]++;
} else {
sum_l[s[i] + 1]++;
}
}
for (int i = 0; i <= upper; i++) {
sum_s[i] += sum_l[i];
if (i < upper) sum_l[i + 1] += sum_s[i];
}
auto induce = [&](const std::vector<int>& lms) {
std::fill(sa.begin(), sa.end(), -1);
std::vector<int> buf(upper + 1);
std::copy(sum_s.begin(), sum_s.end(), buf.begin());
for (auto d : lms) {
if (d == n) continue;
sa[buf[s[d]]++] = d;
}
std::copy(sum_l.begin(), sum_l.end(), buf.begin());
sa[buf[s[n - 1]]++] = n - 1;
for (int i = 0; i < n; i++) {
int v = sa[i];
if (v >= 1 && !ls[v - 1]) {
sa[buf[s[v - 1]]++] = v - 1;
}
}
std::copy(sum_l.begin(), sum_l.end(), buf.begin());
for (int i = n - 1; i >= 0; i--) {
int v = sa[i];
if (v >= 1 && ls[v - 1]) {
sa[--buf[s[v - 1] + 1]] = v - 1;
}
}
};
std::vector<int> lms_map(n + 1, -1);
int m = 0;
for (int i = 1; i < n; i++) {
if (!ls[i - 1] && ls[i]) {
lms_map[i] = m++;
}
}
std::vector<int> lms;
lms.reserve(m);
for (int i = 1; i < n; i++) {
if (!ls[i - 1] && ls[i]) {
lms.push_back(i);
}
}
induce(lms);
if (m) {
std::vector<int> sorted_lms;
sorted_lms.reserve(m);
for (int v : sa) {
if (lms_map[v] != -1) sorted_lms.push_back(v);
}
std::vector<int> rec_s(m);
int rec_upper = 0;
rec_s[lms_map[sorted_lms[0]]] = 0;
for (int i = 1; i < m; i++) {
int l = sorted_lms[i - 1], r = sorted_lms[i];
int end_l = (lms_map[l] + 1 < m) ? lms[lms_map[l] + 1] : n;
int end_r = (lms_map[r] + 1 < m) ? lms[lms_map[r] + 1] : n;
bool same = true;
if (end_l - l != end_r - r) {
same = false;
} else {
while (l < end_l) {
if (s[l] != s[r]) {
break;
}
l++;
r++;
}
if (l == n || s[l] != s[r]) same = false;
}
if (!same) rec_upper++;
rec_s[lms_map[sorted_lms[i]]] = rec_upper;
}
auto rec_sa =
sa_is<THRESHOLD_NAIVE, THRESHOLD_DOUBLING>(rec_s, rec_upper);
for (int i = 0; i < m; i++) {
sorted_lms[i] = lms[rec_sa[i]];
}
induce(sorted_lms);
}
return sa;
}
} // namespace internal
std::vector<int> suffix_array(const std::vector<int>& s, int upper) {
assert(0 <= upper);
for (int d : s) {
assert(0 <= d && d <= upper);
}
auto sa = internal::sa_is(s, upper);
return sa;
}
template <class T> std::vector<int> suffix_array(const std::vector<T>& s) {
int n = int(s.size());
std::vector<int> idx(n);
iota(idx.begin(), idx.end(), 0);
sort(idx.begin(), idx.end(), [&](int l, int r) { return s[l] < s[r]; });
std::vector<int> s2(n);
int now = 0;
for (int i = 0; i < n; i++) {
if (i && s[idx[i - 1]] != s[idx[i]]) now++;
s2[idx[i]] = now;
}
return internal::sa_is(s2, now);
}
std::vector<int> suffix_array(const std::string& s) {
int n = int(s.size());
std::vector<int> s2(n);
for (int i = 0; i < n; i++) {
s2[i] = s[i];
}
return internal::sa_is(s2, 255);
}
// Reference:
// T. Kasai, G. Lee, H. Arimura, S. Arikawa, and K. Park,
// Linear-Time Longest-Common-Prefix Computation in Suffix Arrays and Its
// Applications
template <class T>
std::vector<int> lcp_array(const std::vector<T>& s,
const std::vector<int>& sa) {
int n = int(s.size());
assert(n >= 1);
std::vector<int> rnk(n);
for (int i = 0; i < n; i++) {
rnk[sa[i]] = i;
}
std::vector<int> lcp(n - 1);
int h = 0;
for (int i = 0; i < n; i++) {
if (h > 0) h--;
if (rnk[i] == 0) continue;
int j = sa[rnk[i] - 1];
for (; j + h < n && i + h < n; h++) {
if (s[j + h] != s[i + h]) break;
}
lcp[rnk[i] - 1] = h;
}
return lcp;
}
std::vector<int> lcp_array(const std::string& s, const std::vector<int>& sa) {
int n = int(s.size());
std::vector<int> s2(n);
for (int i = 0; i < n; i++) {
s2[i] = s[i];
}
return lcp_array(s2, sa);
}
// Reference:
// D. Gusfield,
// Algorithms on Strings, Trees, and Sequences: Computer Science and
// Computational Biology
template <class T> std::vector<int> z_algorithm(const std::vector<T>& s) {
int n = int(s.size());
if (n == 0) return {};
std::vector<int> z(n);
z[0] = 0;
for (int i = 1, j = 0; i < n; i++) {
int& k = z[i];
k = (j + z[j] <= i) ? 0 : std::min(j + z[j] - i, z[i - j]);
while (i + k < n && s[k] == s[i + k]) k++;
if (j + z[j] < i + z[i]) j = i;
}
z[0] = n;
return z;
}
std::vector<int> z_algorithm(const std::string& s) {
int n = int(s.size());
std::vector<int> s2(n);
for (int i = 0; i < n; i++) {
s2[i] = s[i];
}
return z_algorithm(s2);
}
} // namespace atcoder
#include <cassert>
#include <vector>
namespace atcoder {
// Reference:
// B. Aspvall, M. Plass, and R. Tarjan,
// A Linear-Time Algorithm for Testing the Truth of Certain Quantified Boolean
// Formulas
struct two_sat {
public:
two_sat() : _n(0), scc(0) {}
two_sat(int n) : _n(n), _answer(n), scc(2 * n) {}
void add_clause(int i, bool f, int j, bool g) {
assert(0 <= i && i < _n);
assert(0 <= j && j < _n);
scc.add_edge(2 * i + (f ? 0 : 1), 2 * j + (g ? 1 : 0));
scc.add_edge(2 * j + (g ? 0 : 1), 2 * i + (f ? 1 : 0));
}
bool satisfiable() {
auto id = scc.scc_ids().second;
for (int i = 0; i < _n; i++) {
if (id[2 * i] == id[2 * i + 1]) return false;
_answer[i] = id[2 * i] < id[2 * i + 1];
}
return true;
}
std::vector<bool> answer() { return _answer; }
private:
int _n;
std::vector<bool> _answer;
internal::scc_graph scc;
};
} // namespace atcoder
using namespace std;
using namespace atcoder;
using ll = long long;
#define ALL(a) (a).begin(), (a).end()
#define FOR(i, a, b) for (long long int i = (a); i <= (b); i++)
#define RFOR(i, a, b) for (long long int i = (a); i >= (b); i--)
const int MOD = 1000000007;
#define LLONG_MAXs 9223372036854775800 / 2
//#define bit(n, k) ((n >> k) & 1) /*n縺ョk bit逶ョ*/
#define ALL(a) (a).begin(), (a).end()
#include <iostream>
#include <cmath>
using namespace std;
bool isPrimeNum(ll x)
{ // 邏�謨ー縺ァ縺ゅk蝣エ蜷� true 繧定ソ斐☆
if (x <= 1)
{ // 1莉・荳九〒縺ゅk蝣エ蜷医��邏�謨ー縺ァ縺ェ縺��%縺ィ縺後☆縺舌↓繧上°繧�
return false;
}
// sqrt( double蝙� ) 縺ッ蠑墓焚縺ョ蟷ウ譁ケ譬ケ繧� double蝙九〒霑斐☆縺ョ縺ァ縲(nt蝙九〒繧ュ繝」繧ケ繝�
int n = (int)sqrt((double)x);
for (int i = 2; i <= n; i++)
{
if (x % i == 0)
{ // 蜑イ繧雁��繧区紛謨ー縺後≠繧句�エ蜷医�∝叉蛻、螳夂オゆコ�
return false;
}
}
return true; // 蜑イ繧雁��繧区紛謨ー縺後↑縺���エ蜷医�∫エ�謨ー縺ァ縺ゅk
}
ll myPow(ll x, ll n, ll m)
{
if (n == 0)
return 1;
if (n % 2 == 0)
return myPow(x * x % m, n / 2, m);
else
return x * myPow(x, n - 1, m) % m;
}
constexpr ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
constexpr ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
constexpr ll abs(ll a, ll b)
{
if (a >= b)
return a - b;
if (a < b)
return b - a;
}
constexpr double dabs(double a, double b)
{
if (a >= b)
return a - b;
if (a < b)
return b - a;
}
constexpr ll min(ll a, ll b)
{
if (a >= b)
return b;
if (a < b)
return a;
}
constexpr ll max(ll a, ll b)
{
if (a >= b)
return a;
if (a < b)
return b;
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int dx8[8] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy8[8] = {0, 1, 0, -1, 1, 1, -1, -1};
class UnionFind
{
public:
//隕ェ縺ョ逡ェ蜿キ繧呈�シ邏阪☆繧九�りヲェ縺�縺」縺溷�エ蜷医��-(縺昴��髮��粋縺ョ繧オ繧、繧コ)
vector<int> Parent;
//菴懊k縺ィ縺阪��Parent縺ョ蛟、繧貞��縺ヲ-1縺ォ縺吶k
//縺薙≧縺吶k縺ィ蜈ィ縺ヲ繝舌Λ繝舌Λ縺ォ縺ェ繧�
UnionFind(int N)
{
Parent = vector<int>(N, -1);
}
//A縺後←縺ョ繧ー繝ォ繝シ繝励↓螻槭@縺ヲ縺��k縺玖ェソ縺ケ繧�
int root(int A)
{
if (Parent[A] < 0)
return A;
return Parent[A] = root(Parent[A]);
}
//閾ェ蛻����縺��k繧ー繝ォ繝シ繝励��鬆らせ謨ー繧定ェソ縺ケ繧�
int size(int A)
{
return -Parent[root(A)]; //隕ェ繧偵→縺」縺ヲ縺阪◆縺Ь
}
bool issame(int x, int y)
{
return root(x) == root(y);
}
//A縺ィB繧偵¥縺」莉倥¢繧�
bool connect(int A, int B)
{
//A縺ィB繧堤峩謗・縺、縺ェ縺舌��縺ァ縺ッ縺ェ縺上�〉oot(A)縺ォroot(B)繧偵¥縺」縺、縺代k
A = root(A);
B = root(B);
if (A == B)
{
//縺吶〒縺ォ縺上▲縺、縺��※繧九°繧峨¥縺」莉倥¢縺ェ縺�
return false;
}
//螟ァ縺阪>譁ケ(A)縺ォ蟆上&縺��⊇縺�(B)繧偵¥縺」莉倥¢縺溘>
//螟ァ蟆上′騾��□縺」縺溘i縺イ縺」縺上j霑斐@縺。繧��≧縲�
if (size(A) < size(B))
swap(A, B);
//A縺ョ繧オ繧、繧コ繧呈峩譁ー縺吶k
Parent[A] += Parent[B];
//B縺ョ隕ェ繧但縺ォ螟画峩縺吶k
Parent[B] = A;
return true;
}
};
long long fac[510000], finv[510000], inv[510000];
// 繝����繝悶Ν繧剃ス懊k蜑榊��逅�
void COMinit()
{
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < 510000; i++)
{
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
// 莠碁���ソよ焚險育ョ�
long long COM(int n, int k)
{
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
long long modinv(long long a, long long m)
{
long long b = m, u = 1, v = 0;
while (b)
{
long long t = a / b;
a -= t * b;
swap(a, b);
u -= t * v;
swap(u, v);
}
u %= m;
if (u < 0)
u += m;
return u;
}
void yn(bool flag)
{
if (flag)
{
cout << "Yes" << endl;
}
else
{
cout << "No" << endl;
}
return;
}
void YN(bool flag)
{
if (flag)
{
cout << "YES" << endl;
}
else
{
cout << "NO" << endl;
}
return;
}
std::vector<ll> enum_div(ll n) //n縺ョ邏��焚繧貞��謖�
{
std::vector<ll> ret;
for (ll i = 1; i * i <= n; ++i)
{
if (n % i == 0)
{
ret.push_back(i);
if (i != 1 && i * i != n)
{
ret.push_back(n / i);
}
}
}
ret.push_back(n);
return ret;
}
// modint: mod 險育ョ励r int 繧呈桶縺��h縺��↓謇ア縺医k讒矩��菴�
template <int MOD>
struct Fp
{
long long val;
constexpr Fp(long long v = 0) noexcept : val(v % MOD)
{
if (val < 0)
val += MOD;
}
constexpr int getmod() { return MOD; }
constexpr Fp operator-() const noexcept
{
return val ? MOD - val : 0;
}
constexpr Fp operator+(const Fp &r) const noexcept { return Fp(*this) += r; }
constexpr Fp operator-(const Fp &r) const noexcept { return Fp(*this) -= r; }
constexpr Fp operator*(const Fp &r) const noexcept { return Fp(*this) *= r; }
constexpr Fp operator/(const Fp &r) const noexcept { return Fp(*this) /= r; }
constexpr Fp &operator+=(const Fp &r) noexcept
{
val += r.val;
if (val >= MOD)
val -= MOD;
return *this;
}
constexpr Fp &operator-=(const Fp &r) noexcept
{
val -= r.val;
if (val < 0)
val += MOD;
return *this;
}
constexpr Fp &operator*=(const Fp &r) noexcept
{
val = val * r.val % MOD;
return *this;
}
constexpr Fp &operator/=(const Fp &r) noexcept
{
long long a = r.val, b = MOD, u = 1, v = 0;
while (b)
{
long long t = a / b;
a -= t * b;
swap(a, b);
u -= t * v;
swap(u, v);
}
val = val * u % MOD;
if (val < 0)
val += MOD;
return *this;
}
constexpr bool operator==(const Fp &r) const noexcept
{
return this->val == r.val;
}
constexpr bool operator!=(const Fp &r) const noexcept
{
return this->val != r.val;
}
friend constexpr ostream &operator<<(ostream &os, const Fp<MOD> &x) noexcept
{
return os << x.val;
}
friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept
{
if (n == 0)
return 1;
auto t = modpow(a, n / 2);
t = t * t;
if (n & 1)
t = t * a;
return t;
}
};
using mint = Fp<MOD>;
// 繧ー繝ゥ繝輔そ繝��ヨ
struct Edge
{
ll to; // 霎コ縺ョ陦後″蜈�
ll weight; // 霎コ縺ョ驥阪∩
Edge(int t, int w) : to(t), weight(w) {}
};
//using Graph = vector<vector<Edge>>;
#define def 0
template <class V, int NV>
struct SegTree
{ //[l,r)
V comp(V &l, V &r) { return max(l, r); };
vector<V> val;
SegTree() { val = vector<V>(NV * 2, def); }
V get(int x, int y, int l = 0, int r = NV, int k = 1)
{
if (r <= x || y <= l)
return def;
if (x <= l && r <= y)
return val[k];
auto a = get(x, y, l, (l + r) / 2, k * 2);
auto b = get(x, y, (l + r) / 2, r, k * 2 + 1);
return comp(a, b);
}
void update(int i, V v)
{
i += NV;
val[i] = v;
while (i > 1)
i >>= 1, val[i] = comp(val[i * 2], val[i * 2 + 1]);
}
void add(int i, V v) { update(i, val[i + NV] + v); }
V operator[](int x) { return get(x, x + 1); }
};
typedef vector<vector<long long>> matrix;
matrix mul_mod(matrix A, matrix B)
{
int H = A.size();
int W = B[0].size();
int K = A[0].size();
matrix C(H, vector<ll>(W, 0));
for (int i = 0; i < H; i++)
{
for (int j = 0; j < W; j++)
{
for (int k = 0; k < K; k++)
{
C[i][j] += A[i][k] * B[k][j];
C[i][j] %= MOD;
}
}
}
return C;
}
// 蛹コ髢灘刈邂励↓繧ょッセ蠢懊@縺� BIT
template <class Abel>
struct BIT
{
vector<Abel> dat[2];
Abel UNITY_SUM = 0; // to be set
/* [1, n] */
BIT(int n) { init(n); }
void init(int n)
{
for (int iter = 0; iter < 2; ++iter)
dat[iter].assign(n + 1, UNITY_SUM);
}
/* a, b are 1-indexed, [a, b) */
inline void sub_add(int p, int a, Abel x)
{
for (int i = a; i < (int)dat[p].size(); i += i & -i)
dat[p][i] = dat[p][i] + x;
}
inline void add(int a, int b, Abel x)
{
sub_add(0, a, x * -(a - 1));
sub_add(1, a, x);
sub_add(0, b, x * (b - 1));
sub_add(1, b, x * (-1));
}
/* a is 1-indexed, [a, b) */
inline Abel sub_sum(int p, int a)
{
Abel res = UNITY_SUM;
for (int i = a; i > 0; i -= i & -i)
res = res + dat[p][i];
return res;
}
inline Abel sum(int a, int b)
{
return sub_sum(0, b - 1) + sub_sum(1, b - 1) * (b - 1) - sub_sum(0, a - 1) - sub_sum(1, a - 1) * (a - 1);
}
/* debug */
void print()
{
for (int i = 1; i < (int)dat[0].size(); ++i)
cout << sum(i, i + 1) << ",";
cout << endl;
}
};
using Graph = vector<vector<ll>>;
void print(const std::vector<int> &v)
{
std::for_each(v.begin(), v.end(), [](int x) {
std::cout << x << " ";
});
std::cout << std::endl;
}
const double PI = 3.14159265358979323846;
ll times_cap(ll a, ll b)
{
if (log10(a) + log10(b) >= 19.0)
return -1;
else
return a * b;
}
// Reference:
// B. Aspvall, M. Plass, and R. Tarjan,
// A Linear-Time Algorithm for Testing the Truth of Certain Quantified Boolean
// Formulas
struct two_sat
{
public:
two_sat() : _n(0), scc(0) {}
two_sat(int n) : _n(n), _answer(n), scc(2 * n) {}
void add_clause(int i, bool f, int j, bool g)
{
assert(0 <= i && i < _n);
assert(0 <= j && j < _n);
scc.add_edge(2 * i + (f ? 0 : 1), 2 * j + (g ? 1 : 0));
scc.add_edge(2 * j + (g ? 0 : 1), 2 * i + (f ? 1 : 0));
}
bool satisfiable()
{
auto id = scc.scc_ids().second;
for (int i = 0; i < _n; i++)
{
if (id[2 * i] == id[2 * i + 1])
return false;
_answer[i] = id[2 * i] < id[2 * i + 1];
}
return true;
}
std::vector<bool> answer() { return _answer; }
private:
int _n;
std::vector<bool> _answer;
internal::scc_graph scc;
};
// konpairu command
// g++ code.cpp -std=c++14 -I .
//cout << std::setprecision(30) << ans << endl;
int main()
{
int n, d;
cin >> n;
vector<int> x(n), y(n);
for (int i = 0; i < n; i++)
{
cin >> x[i] >> y[i];
x[i]--;
y[i]--;
}
int left = 0, right = 1e9;
// ts[i] = (i-th flag is located on x[i])
while (right - left > 1)
{
int mid = left + (right - left) / 2; // 蛹コ髢薙��逵溘s荳ュ
two_sat ts(n);
for (int i = 0; i < n; i++)
{
for (int j = i + 1; j < n; j++)
{
if (abs(x[i] - x[j]) < mid)
{
// cannot use both of x[i] and x[j]
ts.add_clause(i, false, j, false);
}
if (abs(x[i] - y[j]) < mid)
{
ts.add_clause(i, false, j, true);
}
if (abs(y[i] - x[j]) < mid)
{
ts.add_clause(i, true, j, false);
}
if (abs(y[i] - y[j]) < mid)
{
ts.add_clause(i, true, j, true);
}
}
}
/* 蝗樒ュ斐��蠢懊§縺ヲ縲∝ケエ鮨「繧堤オ槭k */
if (ts.satisfiable())
left = mid; // mid 豁ウ莉・荳翫↑繧峨�[id 豁ウ莉・荳� right 豁ウ莉・荳九↓縺ェ繧九h縺��↓
else
right = mid; // mid 豁ウ譛ェ貅�縺ェ繧峨�〕eft 豁ウ莉・荳� mid 豁ウ譛ェ貅�縺ォ縺ェ繧九h縺��↓
//cout << left << mid << right << endl;
}
cout << left << endl;
return 0;
}
| a.cc: In function 'int main()':
a.cc:2589:9: error: reference to 'two_sat' is ambiguous
2589 | two_sat ts(n);
| ^~~~~~~
a.cc:2068:8: note: candidates are: 'struct atcoder::two_sat'
2068 | struct two_sat {
| ^~~~~~~
a.cc:2537:8: note: 'struct two_sat'
2537 | struct two_sat
| ^~~~~~~
a.cc:2597:21: error: 'ts' was not declared in this scope; did you mean 'tm'?
2597 | ts.add_clause(i, false, j, false);
| ^~
| tm
a.cc:2601:21: error: 'ts' was not declared in this scope; did you mean 'tm'?
2601 | ts.add_clause(i, false, j, true);
| ^~
| tm
a.cc:2605:21: error: 'ts' was not declared in this scope; did you mean 'tm'?
2605 | ts.add_clause(i, true, j, false);
| ^~
| tm
a.cc:2609:21: error: 'ts' was not declared in this scope; did you mean 'tm'?
2609 | ts.add_clause(i, true, j, true);
| ^~
| tm
a.cc:2615:13: error: 'ts' was not declared in this scope; did you mean 'tm'?
2615 | if (ts.satisfiable())
| ^~
| tm
|
s888301912 | p03802 | C++ | #include <bits/stdc++.h>
#include <stdio.h>
#include <iostream>
#include <cstdio>
#include <bitset>
#include <algorithm>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <string>
#include <string.h>
#include <cmath>
#include <utility>
#include <functional>
#include <map>
#include <set>
#include <cctype>
#include <fstream>
#include <numeric>
#include <cassert>
#include <cstdint>
#include <iomanip>
#include <cstring>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
using ll = long long;
#define ALL(a) (a).begin(), (a).end()
#define FOR(i, a, b) for (long long int i = (a); i <= (b); i++)
#define RFOR(i, a, b) for (long long int i = (a); i >= (b); i--)
const int MOD = 1000000007;
#define LLONG_MAXs 9223372036854775800 / 2
//#define bit(n, k) ((n >> k) & 1) /*nのk bit目*/
#define ALL(a) (a).begin(), (a).end()
#include <iostream>
#include <cmath>
using namespace std;
bool isPrimeNum(ll x)
{ // 素数である場合 true を返す
if (x <= 1)
{ // 1以下である場合は素数でないことがすぐにわかる
return false;
}
// sqrt( double型 ) は引数の平方根を double型で返すので、int型でキャスト
int n = (int)sqrt((double)x);
for (int i = 2; i <= n; i++)
{
if (x % i == 0)
{ // 割り切る整数がある場合、即判定終了
return false;
}
}
return true; // 割り切る整数がない場合、素数である
}
ll myPow(ll x, ll n, ll m)
{
if (n == 0)
return 1;
if (n % 2 == 0)
return myPow(x * x % m, n / 2, m);
else
return x * myPow(x, n - 1, m) % m;
}
constexpr ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
constexpr ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
constexpr ll abs(ll a, ll b)
{
if (a >= b)
return a - b;
if (a < b)
return b - a;
}
constexpr double dabs(double a, double b)
{
if (a >= b)
return a - b;
if (a < b)
return b - a;
}
constexpr ll min(ll a, ll b)
{
if (a >= b)
return b;
if (a < b)
return a;
}
constexpr ll max(ll a, ll b)
{
if (a >= b)
return a;
if (a < b)
return b;
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int dx8[8] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy8[8] = {0, 1, 0, -1, 1, 1, -1, -1};
class UnionFind
{
public:
//親の番号を格納する。親だった場合は-(その集合のサイズ)
vector<int> Parent;
//作るときはParentの値を全て-1にする
//こうすると全てバラバラになる
UnionFind(int N)
{
Parent = vector<int>(N, -1);
}
//Aがどのグループに属しているか調べる
int root(int A)
{
if (Parent[A] < 0)
return A;
return Parent[A] = root(Parent[A]);
}
//自分のいるグループの頂点数を調べる
int size(int A)
{
return -Parent[root(A)]; //親をとってきたい]
}
bool issame(int x, int y)
{
return root(x) == root(y);
}
//AとBをくっ付ける
bool connect(int A, int B)
{
//AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
A = root(A);
B = root(B);
if (A == B)
{
//すでにくっついてるからくっ付けない
return false;
}
//大きい方(A)に小さいほう(B)をくっ付けたい
//大小が逆だったらひっくり返しちゃう。
if (size(A) < size(B))
swap(A, B);
//Aのサイズを更新する
Parent[A] += Parent[B];
//Bの親をAに変更する
Parent[B] = A;
return true;
}
};
long long fac[510000], finv[510000], inv[510000];
// テーブルを作る前処理
void COMinit()
{
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < 510000; i++)
{
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
// 二項係数計算
long long COM(int n, int k)
{
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
long long modinv(long long a, long long m)
{
long long b = m, u = 1, v = 0;
while (b)
{
long long t = a / b;
a -= t * b;
swap(a, b);
u -= t * v;
swap(u, v);
}
u %= m;
if (u < 0)
u += m;
return u;
}
void yn(bool flag)
{
if (flag)
{
cout << "Yes" << endl;
}
else
{
cout << "No" << endl;
}
return;
}
void YN(bool flag)
{
if (flag)
{
cout << "YES" << endl;
}
else
{
cout << "NO" << endl;
}
return;
}
std::vector<ll> enum_div(ll n) //nの約数を列挙
{
std::vector<ll> ret;
for (ll i = 1; i * i <= n; ++i)
{
if (n % i == 0)
{
ret.push_back(i);
if (i != 1 && i * i != n)
{
ret.push_back(n / i);
}
}
}
ret.push_back(n);
return ret;
}
// modint: mod 計算を int を扱うように扱える構造体
template <int MOD>
struct Fp
{
long long val;
constexpr Fp(long long v = 0) noexcept : val(v % MOD)
{
if (val < 0)
val += MOD;
}
constexpr int getmod() { return MOD; }
constexpr Fp operator-() const noexcept
{
return val ? MOD - val : 0;
}
constexpr Fp operator+(const Fp &r) const noexcept { return Fp(*this) += r; }
constexpr Fp operator-(const Fp &r) const noexcept { return Fp(*this) -= r; }
constexpr Fp operator*(const Fp &r) const noexcept { return Fp(*this) *= r; }
constexpr Fp operator/(const Fp &r) const noexcept { return Fp(*this) /= r; }
constexpr Fp &operator+=(const Fp &r) noexcept
{
val += r.val;
if (val >= MOD)
val -= MOD;
return *this;
}
constexpr Fp &operator-=(const Fp &r) noexcept
{
val -= r.val;
if (val < 0)
val += MOD;
return *this;
}
constexpr Fp &operator*=(const Fp &r) noexcept
{
val = val * r.val % MOD;
return *this;
}
constexpr Fp &operator/=(const Fp &r) noexcept
{
long long a = r.val, b = MOD, u = 1, v = 0;
while (b)
{
long long t = a / b;
a -= t * b;
swap(a, b);
u -= t * v;
swap(u, v);
}
val = val * u % MOD;
if (val < 0)
val += MOD;
return *this;
}
constexpr bool operator==(const Fp &r) const noexcept
{
return this->val == r.val;
}
constexpr bool operator!=(const Fp &r) const noexcept
{
return this->val != r.val;
}
friend constexpr ostream &operator<<(ostream &os, const Fp<MOD> &x) noexcept
{
return os << x.val;
}
friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept
{
if (n == 0)
return 1;
auto t = modpow(a, n / 2);
t = t * t;
if (n & 1)
t = t * a;
return t;
}
};
using mint = Fp<MOD>;
// グラフセット
struct Edge
{
ll to; // 辺の行き先
ll weight; // 辺の重み
Edge(int t, int w) : to(t), weight(w) {}
};
//using Graph = vector<vector<Edge>>;
#define def 0
template <class V, int NV>
struct SegTree
{ //[l,r)
V comp(V &l, V &r) { return max(l, r); };
vector<V> val;
SegTree() { val = vector<V>(NV * 2, def); }
V get(int x, int y, int l = 0, int r = NV, int k = 1)
{
if (r <= x || y <= l)
return def;
if (x <= l && r <= y)
return val[k];
auto a = get(x, y, l, (l + r) / 2, k * 2);
auto b = get(x, y, (l + r) / 2, r, k * 2 + 1);
return comp(a, b);
}
void update(int i, V v)
{
i += NV;
val[i] = v;
while (i > 1)
i >>= 1, val[i] = comp(val[i * 2], val[i * 2 + 1]);
}
void add(int i, V v) { update(i, val[i + NV] + v); }
V operator[](int x) { return get(x, x + 1); }
};
typedef vector<vector<long long>> matrix;
matrix mul_mod(matrix A, matrix B)
{
int H = A.size();
int W = B[0].size();
int K = A[0].size();
matrix C(H, vector<ll>(W, 0));
for (int i = 0; i < H; i++)
{
for (int j = 0; j < W; j++)
{
for (int k = 0; k < K; k++)
{
C[i][j] += A[i][k] * B[k][j];
C[i][j] %= MOD;
}
}
}
return C;
}
// 区間加算にも対応した BIT
template <class Abel>
struct BIT
{
vector<Abel> dat[2];
Abel UNITY_SUM = 0; // to be set
/* [1, n] */
BIT(int n) { init(n); }
void init(int n)
{
for (int iter = 0; iter < 2; ++iter)
dat[iter].assign(n + 1, UNITY_SUM);
}
/* a, b are 1-indexed, [a, b) */
inline void sub_add(int p, int a, Abel x)
{
for (int i = a; i < (int)dat[p].size(); i += i & -i)
dat[p][i] = dat[p][i] + x;
}
inline void add(int a, int b, Abel x)
{
sub_add(0, a, x * -(a - 1));
sub_add(1, a, x);
sub_add(0, b, x * (b - 1));
sub_add(1, b, x * (-1));
}
/* a is 1-indexed, [a, b) */
inline Abel sub_sum(int p, int a)
{
Abel res = UNITY_SUM;
for (int i = a; i > 0; i -= i & -i)
res = res + dat[p][i];
return res;
}
inline Abel sum(int a, int b)
{
return sub_sum(0, b - 1) + sub_sum(1, b - 1) * (b - 1) - sub_sum(0, a - 1) - sub_sum(1, a - 1) * (a - 1);
}
/* debug */
void print()
{
for (int i = 1; i < (int)dat[0].size(); ++i)
cout << sum(i, i + 1) << ",";
cout << endl;
}
};
using Graph = vector<vector<ll>>;
void print(const std::vector<int> &v)
{
std::for_each(v.begin(), v.end(), [](int x) {
std::cout << x << " ";
});
std::cout << std::endl;
}
const double PI = 3.14159265358979323846;
ll times_cap(ll a, ll b)
{
if (log10(a) + log10(b) >= 19.0)
return -1;
else
return a * b;
}
// Reference:
// B. Aspvall, M. Plass, and R. Tarjan,
// A Linear-Time Algorithm for Testing the Truth of Certain Quantified Boolean
// Formulas
struct two_sat
{
public:
two_sat() : _n(0), scc(0) {}
two_sat(int n) : _n(n), _answer(n), scc(2 * n) {}
void add_clause(int i, bool f, int j, bool g)
{
assert(0 <= i && i < _n);
assert(0 <= j && j < _n);
scc.add_edge(2 * i + (f ? 0 : 1), 2 * j + (g ? 1 : 0));
scc.add_edge(2 * j + (g ? 0 : 1), 2 * i + (f ? 1 : 0));
}
bool satisfiable()
{
auto id = scc.scc_ids().second;
for (int i = 0; i < _n; i++)
{
if (id[2 * i] == id[2 * i + 1])
return false;
_answer[i] = id[2 * i] < id[2 * i + 1];
}
return true;
}
std::vector<bool> answer() { return _answer; }
private:
int _n;
std::vector<bool> _answer;
internal::scc_graph scc;
};
// konpairu command
// g++ code.cpp -std=c++14 -I .
//cout << std::setprecision(30) << ans << endl;
int main()
{
int n, d;
cin >> n;
vector<int> x(n), y(n);
for (int i = 0; i < n; i++)
{
cin >> x[i] >> y[i];
x[i]--;
y[i]--;
}
int left = 0, right = 1e9;
// ts[i] = (i-th flag is located on x[i])
while (right - left > 1)
{
int mid = left + (right - left) / 2; // 区間の真ん中
two_sat ts(n);
for (int i = 0; i < n; i++)
{
for (int j = i + 1; j < n; j++)
{
if (abs(x[i] - x[j]) < mid)
{
// cannot use both of x[i] and x[j]
ts.add_clause(i, false, j, false);
}
if (abs(x[i] - y[j]) < mid)
{
ts.add_clause(i, false, j, true);
}
if (abs(y[i] - x[j]) < mid)
{
ts.add_clause(i, true, j, false);
}
if (abs(y[i] - y[j]) < mid)
{
ts.add_clause(i, true, j, true);
}
}
}
/* 回答の応じて、年齢を絞る */
if (ts.satisfiable())
left = mid; // mid 歳以上なら、mid 歳以上 right 歳以下になるように
else
right = mid; // mid 歳未満なら、left 歳以上 mid 歳未満になるように
//cout << left << mid << right << endl;
}
cout << left << endl;
return 0;
} | a.cc:496:5: error: 'internal' does not name a type
496 | internal::scc_graph scc;
| ^~~~~~~~
a.cc: In constructor 'two_sat::two_sat()':
a.cc:470:24: error: class 'two_sat' does not have any field named 'scc'
470 | two_sat() : _n(0), scc(0) {}
| ^~~
a.cc: In constructor 'two_sat::two_sat(int)':
a.cc:471:41: error: class 'two_sat' does not have any field named 'scc'
471 | two_sat(int n) : _n(n), _answer(n), scc(2 * n) {}
| ^~~
a.cc: In member function 'void two_sat::add_clause(int, bool, int, bool)':
a.cc:477:9: error: 'scc' was not declared in this scope
477 | scc.add_edge(2 * i + (f ? 0 : 1), 2 * j + (g ? 1 : 0));
| ^~~
a.cc: In member function 'bool two_sat::satisfiable()':
a.cc:482:19: error: 'scc' was not declared in this scope
482 | auto id = scc.scc_ids().second;
| ^~~
|
s464472705 | p03802 | C++ | #include <bits/stdc++.h>
#include <stdio.h>
#include <iostream>
#include <cstdio>
#include <bitset>
#include <algorithm>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <string>
#include <string.h>
#include <cmath>
#include <utility>
#include <functional>
#include <map>
#include <set>
#include <cctype>
#include <fstream>
#include <numeric>
#include <cassert>
#include <cstdint>
#include <iomanip>
#include <cstring>
//#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
#define ALL(a) (a).begin(), (a).end()
#define FOR(i, a, b) for (long long int i = (a); i <= (b); i++)
#define RFOR(i, a, b) for (long long int i = (a); i >= (b); i--)
const int MOD = 1000000007;
#define LLONG_MAXs 9223372036854775800 / 2
//#define bit(n, k) ((n >> k) & 1) /*nのk bit目*/
#define ALL(a) (a).begin(), (a).end()
#include <iostream>
#include <cmath>
using namespace std;
bool isPrimeNum(ll x)
{ // 素数である場合 true を返す
if (x <= 1)
{ // 1以下である場合は素数でないことがすぐにわかる
return false;
}
// sqrt( double型 ) は引数の平方根を double型で返すので、int型でキャスト
int n = (int)sqrt((double)x);
for (int i = 2; i <= n; i++)
{
if (x % i == 0)
{ // 割り切る整数がある場合、即判定終了
return false;
}
}
return true; // 割り切る整数がない場合、素数である
}
ll myPow(ll x, ll n, ll m)
{
if (n == 0)
return 1;
if (n % 2 == 0)
return myPow(x * x % m, n / 2, m);
else
return x * myPow(x, n - 1, m) % m;
}
constexpr ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
constexpr ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
constexpr ll abs(ll a, ll b)
{
if (a >= b)
return a - b;
if (a < b)
return b - a;
}
constexpr double dabs(double a, double b)
{
if (a >= b)
return a - b;
if (a < b)
return b - a;
}
constexpr ll min(ll a, ll b)
{
if (a >= b)
return b;
if (a < b)
return a;
}
constexpr ll max(ll a, ll b)
{
if (a >= b)
return a;
if (a < b)
return b;
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int dx8[8] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy8[8] = {0, 1, 0, -1, 1, 1, -1, -1};
class UnionFind
{
public:
//親の番号を格納する。親だった場合は-(その集合のサイズ)
vector<int> Parent;
//作るときはParentの値を全て-1にする
//こうすると全てバラバラになる
UnionFind(int N)
{
Parent = vector<int>(N, -1);
}
//Aがどのグループに属しているか調べる
int root(int A)
{
if (Parent[A] < 0)
return A;
return Parent[A] = root(Parent[A]);
}
//自分のいるグループの頂点数を調べる
int size(int A)
{
return -Parent[root(A)]; //親をとってきたい]
}
bool issame(int x, int y)
{
return root(x) == root(y);
}
//AとBをくっ付ける
bool connect(int A, int B)
{
//AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
A = root(A);
B = root(B);
if (A == B)
{
//すでにくっついてるからくっ付けない
return false;
}
//大きい方(A)に小さいほう(B)をくっ付けたい
//大小が逆だったらひっくり返しちゃう。
if (size(A) < size(B))
swap(A, B);
//Aのサイズを更新する
Parent[A] += Parent[B];
//Bの親をAに変更する
Parent[B] = A;
return true;
}
};
long long fac[510000], finv[510000], inv[510000];
// テーブルを作る前処理
void COMinit()
{
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < 510000; i++)
{
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
// 二項係数計算
long long COM(int n, int k)
{
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
long long modinv(long long a, long long m)
{
long long b = m, u = 1, v = 0;
while (b)
{
long long t = a / b;
a -= t * b;
swap(a, b);
u -= t * v;
swap(u, v);
}
u %= m;
if (u < 0)
u += m;
return u;
}
void yn(bool flag)
{
if (flag)
{
cout << "Yes" << endl;
}
else
{
cout << "No" << endl;
}
return;
}
void YN(bool flag)
{
if (flag)
{
cout << "YES" << endl;
}
else
{
cout << "NO" << endl;
}
return;
}
std::vector<ll> enum_div(ll n) //nの約数を列挙
{
std::vector<ll> ret;
for (ll i = 1; i * i <= n; ++i)
{
if (n % i == 0)
{
ret.push_back(i);
if (i != 1 && i * i != n)
{
ret.push_back(n / i);
}
}
}
ret.push_back(n);
return ret;
}
// modint: mod 計算を int を扱うように扱える構造体
template <int MOD>
struct Fp
{
long long val;
constexpr Fp(long long v = 0) noexcept : val(v % MOD)
{
if (val < 0)
val += MOD;
}
constexpr int getmod() { return MOD; }
constexpr Fp operator-() const noexcept
{
return val ? MOD - val : 0;
}
constexpr Fp operator+(const Fp &r) const noexcept { return Fp(*this) += r; }
constexpr Fp operator-(const Fp &r) const noexcept { return Fp(*this) -= r; }
constexpr Fp operator*(const Fp &r) const noexcept { return Fp(*this) *= r; }
constexpr Fp operator/(const Fp &r) const noexcept { return Fp(*this) /= r; }
constexpr Fp &operator+=(const Fp &r) noexcept
{
val += r.val;
if (val >= MOD)
val -= MOD;
return *this;
}
constexpr Fp &operator-=(const Fp &r) noexcept
{
val -= r.val;
if (val < 0)
val += MOD;
return *this;
}
constexpr Fp &operator*=(const Fp &r) noexcept
{
val = val * r.val % MOD;
return *this;
}
constexpr Fp &operator/=(const Fp &r) noexcept
{
long long a = r.val, b = MOD, u = 1, v = 0;
while (b)
{
long long t = a / b;
a -= t * b;
swap(a, b);
u -= t * v;
swap(u, v);
}
val = val * u % MOD;
if (val < 0)
val += MOD;
return *this;
}
constexpr bool operator==(const Fp &r) const noexcept
{
return this->val == r.val;
}
constexpr bool operator!=(const Fp &r) const noexcept
{
return this->val != r.val;
}
friend constexpr ostream &operator<<(ostream &os, const Fp<MOD> &x) noexcept
{
return os << x.val;
}
friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept
{
if (n == 0)
return 1;
auto t = modpow(a, n / 2);
t = t * t;
if (n & 1)
t = t * a;
return t;
}
};
using mint = Fp<MOD>;
// グラフセット
struct Edge
{
ll to; // 辺の行き先
ll weight; // 辺の重み
Edge(int t, int w) : to(t), weight(w) {}
};
//using Graph = vector<vector<Edge>>;
#define def 0
template <class V, int NV>
struct SegTree
{ //[l,r)
V comp(V &l, V &r) { return max(l, r); };
vector<V> val;
SegTree() { val = vector<V>(NV * 2, def); }
V get(int x, int y, int l = 0, int r = NV, int k = 1)
{
if (r <= x || y <= l)
return def;
if (x <= l && r <= y)
return val[k];
auto a = get(x, y, l, (l + r) / 2, k * 2);
auto b = get(x, y, (l + r) / 2, r, k * 2 + 1);
return comp(a, b);
}
void update(int i, V v)
{
i += NV;
val[i] = v;
while (i > 1)
i >>= 1, val[i] = comp(val[i * 2], val[i * 2 + 1]);
}
void add(int i, V v) { update(i, val[i + NV] + v); }
V operator[](int x) { return get(x, x + 1); }
};
typedef vector<vector<long long>> matrix;
matrix mul_mod(matrix A, matrix B)
{
int H = A.size();
int W = B[0].size();
int K = A[0].size();
matrix C(H, vector<ll>(W, 0));
for (int i = 0; i < H; i++)
{
for (int j = 0; j < W; j++)
{
for (int k = 0; k < K; k++)
{
C[i][j] += A[i][k] * B[k][j];
C[i][j] %= MOD;
}
}
}
return C;
}
// 区間加算にも対応した BIT
template <class Abel>
struct BIT
{
vector<Abel> dat[2];
Abel UNITY_SUM = 0; // to be set
/* [1, n] */
BIT(int n) { init(n); }
void init(int n)
{
for (int iter = 0; iter < 2; ++iter)
dat[iter].assign(n + 1, UNITY_SUM);
}
/* a, b are 1-indexed, [a, b) */
inline void sub_add(int p, int a, Abel x)
{
for (int i = a; i < (int)dat[p].size(); i += i & -i)
dat[p][i] = dat[p][i] + x;
}
inline void add(int a, int b, Abel x)
{
sub_add(0, a, x * -(a - 1));
sub_add(1, a, x);
sub_add(0, b, x * (b - 1));
sub_add(1, b, x * (-1));
}
/* a is 1-indexed, [a, b) */
inline Abel sub_sum(int p, int a)
{
Abel res = UNITY_SUM;
for (int i = a; i > 0; i -= i & -i)
res = res + dat[p][i];
return res;
}
inline Abel sum(int a, int b)
{
return sub_sum(0, b - 1) + sub_sum(1, b - 1) * (b - 1) - sub_sum(0, a - 1) - sub_sum(1, a - 1) * (a - 1);
}
/* debug */
void print()
{
for (int i = 1; i < (int)dat[0].size(); ++i)
cout << sum(i, i + 1) << ",";
cout << endl;
}
};
using Graph = vector<vector<ll>>;
void print(const std::vector<int> &v)
{
std::for_each(v.begin(), v.end(), [](int x) {
std::cout << x << " ";
});
std::cout << std::endl;
}
const double PI = 3.14159265358979323846;
ll times_cap(ll a, ll b)
{
if (log10(a) + log10(b) >= 19.0)
return -1;
else
return a * b;
}
// Reference:
// B. Aspvall, M. Plass, and R. Tarjan,
// A Linear-Time Algorithm for Testing the Truth of Certain Quantified Boolean
// Formulas
struct two_sat
{
public:
two_sat() : _n(0), scc(0) {}
two_sat(int n) : _n(n), _answer(n), scc(2 * n) {}
void add_clause(int i, bool f, int j, bool g)
{
assert(0 <= i && i < _n);
assert(0 <= j && j < _n);
scc.add_edge(2 * i + (f ? 0 : 1), 2 * j + (g ? 1 : 0));
scc.add_edge(2 * j + (g ? 0 : 1), 2 * i + (f ? 1 : 0));
}
bool satisfiable()
{
auto id = scc.scc_ids().second;
for (int i = 0; i < _n; i++)
{
if (id[2 * i] == id[2 * i + 1])
return false;
_answer[i] = id[2 * i] < id[2 * i + 1];
}
return true;
}
std::vector<bool> answer() { return _answer; }
private:
int _n;
std::vector<bool> _answer;
internal::scc_graph scc;
};
// konpairu command
// g++ code.cpp -std=c++14 -I .
//cout << std::setprecision(30) << ans << endl;
int main()
{
int n, d;
cin >> n;
vector<int> x(n), y(n);
for (int i = 0; i < n; i++)
{
cin >> x[i] >> y[i];
x[i]--;
y[i]--;
}
int left = 0, right = 1e9;
// ts[i] = (i-th flag is located on x[i])
while (right - left > 1)
{
int mid = left + (right - left) / 2; // 区間の真ん中
two_sat ts(n);
for (int i = 0; i < n; i++)
{
for (int j = i + 1; j < n; j++)
{
if (abs(x[i] - x[j]) < mid)
{
// cannot use both of x[i] and x[j]
ts.add_clause(i, false, j, false);
}
if (abs(x[i] - y[j]) < mid)
{
ts.add_clause(i, false, j, true);
}
if (abs(y[i] - x[j]) < mid)
{
ts.add_clause(i, true, j, false);
}
if (abs(y[i] - y[j]) < mid)
{
ts.add_clause(i, true, j, true);
}
}
}
/* 回答の応じて、年齢を絞る */
if (ts.satisfiable())
left = mid; // mid 歳以上なら、mid 歳以上 right 歳以下になるように
else
right = mid; // mid 歳未満なら、left 歳以上 mid 歳未満になるように
//cout << left << mid << right << endl;
}
cout << left << endl;
return 0;
} | a.cc:29:17: error: 'atcoder' is not a namespace-name
29 | using namespace atcoder;
| ^~~~~~~
a.cc:496:5: error: 'internal' does not name a type
496 | internal::scc_graph scc;
| ^~~~~~~~
a.cc: In constructor 'two_sat::two_sat()':
a.cc:470:24: error: class 'two_sat' does not have any field named 'scc'
470 | two_sat() : _n(0), scc(0) {}
| ^~~
a.cc: In constructor 'two_sat::two_sat(int)':
a.cc:471:41: error: class 'two_sat' does not have any field named 'scc'
471 | two_sat(int n) : _n(n), _answer(n), scc(2 * n) {}
| ^~~
a.cc: In member function 'void two_sat::add_clause(int, bool, int, bool)':
a.cc:477:9: error: 'scc' was not declared in this scope
477 | scc.add_edge(2 * i + (f ? 0 : 1), 2 * j + (g ? 1 : 0));
| ^~~
a.cc: In member function 'bool two_sat::satisfiable()':
a.cc:482:19: error: 'scc' was not declared in this scope
482 | auto id = scc.scc_ids().second;
| ^~~
|
s111626160 | p03802 | C++ | #include <bits/stdc++.h>
#include <stdio.h>
#include <iostream>
#include <cstdio>
#include <bitset>
#include <algorithm>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <string>
#include <string.h>
#include <cmath>
#include <utility>
#include <functional>
#include <map>
#include <set>
#include <cctype>
#include <fstream>
#include <numeric>
#include <cassert>
#include <cstdint>
#include <iomanip>
#include <cstring>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
#define ALL(a) (a).begin(), (a).end()
#define FOR(i, a, b) for (long long int i = (a); i <= (b); i++)
#define RFOR(i, a, b) for (long long int i = (a); i >= (b); i--)
const int MOD = 1000000007;
#define LLONG_MAXs 9223372036854775800 / 2
//#define bit(n, k) ((n >> k) & 1) /*nのk bit目*/
#define ALL(a) (a).begin(), (a).end()
#include <iostream>
#include <cmath>
using namespace std;
bool isPrimeNum(ll x)
{ // 素数である場合 true を返す
if (x <= 1)
{ // 1以下である場合は素数でないことがすぐにわかる
return false;
}
// sqrt( double型 ) は引数の平方根を double型で返すので、int型でキャスト
int n = (int)sqrt((double)x);
for (int i = 2; i <= n; i++)
{
if (x % i == 0)
{ // 割り切る整数がある場合、即判定終了
return false;
}
}
return true; // 割り切る整数がない場合、素数である
}
ll myPow(ll x, ll n, ll m)
{
if (n == 0)
return 1;
if (n % 2 == 0)
return myPow(x * x % m, n / 2, m);
else
return x * myPow(x, n - 1, m) % m;
}
constexpr ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
constexpr ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
constexpr ll abs(ll a, ll b)
{
if (a >= b)
return a - b;
if (a < b)
return b - a;
}
constexpr double dabs(double a, double b)
{
if (a >= b)
return a - b;
if (a < b)
return b - a;
}
constexpr ll min(ll a, ll b)
{
if (a >= b)
return b;
if (a < b)
return a;
}
constexpr ll max(ll a, ll b)
{
if (a >= b)
return a;
if (a < b)
return b;
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int dx8[8] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy8[8] = {0, 1, 0, -1, 1, 1, -1, -1};
class UnionFind
{
public:
//親の番号を格納する。親だった場合は-(その集合のサイズ)
vector<int> Parent;
//作るときはParentの値を全て-1にする
//こうすると全てバラバラになる
UnionFind(int N)
{
Parent = vector<int>(N, -1);
}
//Aがどのグループに属しているか調べる
int root(int A)
{
if (Parent[A] < 0)
return A;
return Parent[A] = root(Parent[A]);
}
//自分のいるグループの頂点数を調べる
int size(int A)
{
return -Parent[root(A)]; //親をとってきたい]
}
bool issame(int x, int y)
{
return root(x) == root(y);
}
//AとBをくっ付ける
bool connect(int A, int B)
{
//AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
A = root(A);
B = root(B);
if (A == B)
{
//すでにくっついてるからくっ付けない
return false;
}
//大きい方(A)に小さいほう(B)をくっ付けたい
//大小が逆だったらひっくり返しちゃう。
if (size(A) < size(B))
swap(A, B);
//Aのサイズを更新する
Parent[A] += Parent[B];
//Bの親をAに変更する
Parent[B] = A;
return true;
}
};
long long fac[510000], finv[510000], inv[510000];
// テーブルを作る前処理
void COMinit()
{
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < 510000; i++)
{
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
// 二項係数計算
long long COM(int n, int k)
{
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
long long modinv(long long a, long long m)
{
long long b = m, u = 1, v = 0;
while (b)
{
long long t = a / b;
a -= t * b;
swap(a, b);
u -= t * v;
swap(u, v);
}
u %= m;
if (u < 0)
u += m;
return u;
}
void yn(bool flag)
{
if (flag)
{
cout << "Yes" << endl;
}
else
{
cout << "No" << endl;
}
return;
}
void YN(bool flag)
{
if (flag)
{
cout << "YES" << endl;
}
else
{
cout << "NO" << endl;
}
return;
}
std::vector<ll> enum_div(ll n) //nの約数を列挙
{
std::vector<ll> ret;
for (ll i = 1; i * i <= n; ++i)
{
if (n % i == 0)
{
ret.push_back(i);
if (i != 1 && i * i != n)
{
ret.push_back(n / i);
}
}
}
ret.push_back(n);
return ret;
}
// modint: mod 計算を int を扱うように扱える構造体
template <int MOD>
struct Fp
{
long long val;
constexpr Fp(long long v = 0) noexcept : val(v % MOD)
{
if (val < 0)
val += MOD;
}
constexpr int getmod() { return MOD; }
constexpr Fp operator-() const noexcept
{
return val ? MOD - val : 0;
}
constexpr Fp operator+(const Fp &r) const noexcept { return Fp(*this) += r; }
constexpr Fp operator-(const Fp &r) const noexcept { return Fp(*this) -= r; }
constexpr Fp operator*(const Fp &r) const noexcept { return Fp(*this) *= r; }
constexpr Fp operator/(const Fp &r) const noexcept { return Fp(*this) /= r; }
constexpr Fp &operator+=(const Fp &r) noexcept
{
val += r.val;
if (val >= MOD)
val -= MOD;
return *this;
}
constexpr Fp &operator-=(const Fp &r) noexcept
{
val -= r.val;
if (val < 0)
val += MOD;
return *this;
}
constexpr Fp &operator*=(const Fp &r) noexcept
{
val = val * r.val % MOD;
return *this;
}
constexpr Fp &operator/=(const Fp &r) noexcept
{
long long a = r.val, b = MOD, u = 1, v = 0;
while (b)
{
long long t = a / b;
a -= t * b;
swap(a, b);
u -= t * v;
swap(u, v);
}
val = val * u % MOD;
if (val < 0)
val += MOD;
return *this;
}
constexpr bool operator==(const Fp &r) const noexcept
{
return this->val == r.val;
}
constexpr bool operator!=(const Fp &r) const noexcept
{
return this->val != r.val;
}
friend constexpr ostream &operator<<(ostream &os, const Fp<MOD> &x) noexcept
{
return os << x.val;
}
friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept
{
if (n == 0)
return 1;
auto t = modpow(a, n / 2);
t = t * t;
if (n & 1)
t = t * a;
return t;
}
};
using mint = Fp<MOD>;
// グラフセット
struct Edge
{
ll to; // 辺の行き先
ll weight; // 辺の重み
Edge(int t, int w) : to(t), weight(w) {}
};
//using Graph = vector<vector<Edge>>;
#define def 0
template <class V, int NV>
struct SegTree
{ //[l,r)
V comp(V &l, V &r) { return max(l, r); };
vector<V> val;
SegTree() { val = vector<V>(NV * 2, def); }
V get(int x, int y, int l = 0, int r = NV, int k = 1)
{
if (r <= x || y <= l)
return def;
if (x <= l && r <= y)
return val[k];
auto a = get(x, y, l, (l + r) / 2, k * 2);
auto b = get(x, y, (l + r) / 2, r, k * 2 + 1);
return comp(a, b);
}
void update(int i, V v)
{
i += NV;
val[i] = v;
while (i > 1)
i >>= 1, val[i] = comp(val[i * 2], val[i * 2 + 1]);
}
void add(int i, V v) { update(i, val[i + NV] + v); }
V operator[](int x) { return get(x, x + 1); }
};
typedef vector<vector<long long>> matrix;
matrix mul_mod(matrix A, matrix B)
{
int H = A.size();
int W = B[0].size();
int K = A[0].size();
matrix C(H, vector<ll>(W, 0));
for (int i = 0; i < H; i++)
{
for (int j = 0; j < W; j++)
{
for (int k = 0; k < K; k++)
{
C[i][j] += A[i][k] * B[k][j];
C[i][j] %= MOD;
}
}
}
return C;
}
// 区間加算にも対応した BIT
template <class Abel>
struct BIT
{
vector<Abel> dat[2];
Abel UNITY_SUM = 0; // to be set
/* [1, n] */
BIT(int n) { init(n); }
void init(int n)
{
for (int iter = 0; iter < 2; ++iter)
dat[iter].assign(n + 1, UNITY_SUM);
}
/* a, b are 1-indexed, [a, b) */
inline void sub_add(int p, int a, Abel x)
{
for (int i = a; i < (int)dat[p].size(); i += i & -i)
dat[p][i] = dat[p][i] + x;
}
inline void add(int a, int b, Abel x)
{
sub_add(0, a, x * -(a - 1));
sub_add(1, a, x);
sub_add(0, b, x * (b - 1));
sub_add(1, b, x * (-1));
}
/* a is 1-indexed, [a, b) */
inline Abel sub_sum(int p, int a)
{
Abel res = UNITY_SUM;
for (int i = a; i > 0; i -= i & -i)
res = res + dat[p][i];
return res;
}
inline Abel sum(int a, int b)
{
return sub_sum(0, b - 1) + sub_sum(1, b - 1) * (b - 1) - sub_sum(0, a - 1) - sub_sum(1, a - 1) * (a - 1);
}
/* debug */
void print()
{
for (int i = 1; i < (int)dat[0].size(); ++i)
cout << sum(i, i + 1) << ",";
cout << endl;
}
};
using Graph = vector<vector<ll>>;
void print(const std::vector<int> &v)
{
std::for_each(v.begin(), v.end(), [](int x) {
std::cout << x << " ";
});
std::cout << std::endl;
}
const double PI = 3.14159265358979323846;
ll times_cap(ll a, ll b)
{
if (log10(a) + log10(b) >= 19.0)
return -1;
else
return a * b;
}
// Reference:
// B. Aspvall, M. Plass, and R. Tarjan,
// A Linear-Time Algorithm for Testing the Truth of Certain Quantified Boolean
// Formulas
struct two_sat
{
public:
two_sat() : _n(0), scc(0) {}
two_sat(int n) : _n(n), _answer(n), scc(2 * n) {}
void add_clause(int i, bool f, int j, bool g)
{
assert(0 <= i && i < _n);
assert(0 <= j && j < _n);
scc.add_edge(2 * i + (f ? 0 : 1), 2 * j + (g ? 1 : 0));
scc.add_edge(2 * j + (g ? 0 : 1), 2 * i + (f ? 1 : 0));
}
bool satisfiable()
{
auto id = scc.scc_ids().second;
for (int i = 0; i < _n; i++)
{
if (id[2 * i] == id[2 * i + 1])
return false;
_answer[i] = id[2 * i] < id[2 * i + 1];
}
return true;
}
std::vector<bool> answer() { return _answer; }
private:
int _n;
std::vector<bool> _answer;
internal::scc_graph scc;
};
// konpairu command
// g++ code.cpp -std=c++14 -I .
//cout << std::setprecision(30) << ans << endl;
int main()
{
int n, d;
cin >> n;
vector<int> x(n), y(n);
for (int i = 0; i < n; i++)
{
cin >> x[i] >> y[i];
x[i]--;
y[i]--;
}
int left = 0, right = 1e9;
// ts[i] = (i-th flag is located on x[i])
while (right - left > 1)
{
int mid = left + (right - left) / 2; // 区間の真ん中
two_sat ts(n);
for (int i = 0; i < n; i++)
{
for (int j = i + 1; j < n; j++)
{
if (abs(x[i] - x[j]) < mid)
{
// cannot use both of x[i] and x[j]
ts.add_clause(i, false, j, false);
}
if (abs(x[i] - y[j]) < mid)
{
ts.add_clause(i, false, j, true);
}
if (abs(y[i] - x[j]) < mid)
{
ts.add_clause(i, true, j, false);
}
if (abs(y[i] - y[j]) < mid)
{
ts.add_clause(i, true, j, true);
}
}
}
/* 回答の応じて、年齢を絞る */
if (ts.satisfiable())
left = mid; // mid 歳以上なら、mid 歳以上 right 歳以下になるように
else
right = mid; // mid 歳未満なら、left 歳以上 mid 歳未満になるように
//cout << left << mid << right << endl;
}
cout << left << endl;
return 0;
} | a.cc:26:10: fatal error: atcoder/all: No such file or directory
26 | #include <atcoder/all>
| ^~~~~~~~~~~~~
compilation terminated.
|
s935864428 | p03802 | C++ | #include <bits/stdc++.h>
#include <stdio.h>
#include <iostream>
#include <cstdio>
#include <bitset>
#include <algorithm>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <string>
#include <string.h>
#include <cmath>
#include <utility>
#include <functional>
#include <map>
#include <set>
#include <cctype>
#include <fstream>
#include <numeric>
#include <cassert>
#include <cstdint>
#include <iomanip>
#include <cstring>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
#define ALL(a) (a).begin(), (a).end()
#define FOR(i, a, b) for (long long int i = (a); i <= (b); i++)
#define RFOR(i, a, b) for (long long int i = (a); i >= (b); i--)
const int MOD = 1000000007;
#define LLONG_MAXs 9223372036854775800 / 2
//#define bit(n, k) ((n >> k) & 1) /*nのk bit目*/
#define ALL(a) (a).begin(), (a).end()
#include <iostream>
#include <cmath>
using namespace std;
bool isPrimeNum(ll x)
{ // 素数である場合 true を返す
if (x <= 1)
{ // 1以下である場合は素数でないことがすぐにわかる
return false;
}
// sqrt( double型 ) は引数の平方根を double型で返すので、int型でキャスト
int n = (int)sqrt((double)x);
for (int i = 2; i <= n; i++)
{
if (x % i == 0)
{ // 割り切る整数がある場合、即判定終了
return false;
}
}
return true; // 割り切る整数がない場合、素数である
}
ll myPow(ll x, ll n, ll m)
{
if (n == 0)
return 1;
if (n % 2 == 0)
return myPow(x * x % m, n / 2, m);
else
return x * myPow(x, n - 1, m) % m;
}
constexpr ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
constexpr ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
constexpr ll abs(ll a, ll b)
{
if (a >= b)
return a - b;
if (a < b)
return b - a;
}
constexpr double dabs(double a, double b)
{
if (a >= b)
return a - b;
if (a < b)
return b - a;
}
constexpr ll min(ll a, ll b)
{
if (a >= b)
return b;
if (a < b)
return a;
}
constexpr ll max(ll a, ll b)
{
if (a >= b)
return a;
if (a < b)
return b;
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int dx8[8] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy8[8] = {0, 1, 0, -1, 1, 1, -1, -1};
class UnionFind
{
public:
//親の番号を格納する。親だった場合は-(その集合のサイズ)
vector<int> Parent;
//作るときはParentの値を全て-1にする
//こうすると全てバラバラになる
UnionFind(int N)
{
Parent = vector<int>(N, -1);
}
//Aがどのグループに属しているか調べる
int root(int A)
{
if (Parent[A] < 0)
return A;
return Parent[A] = root(Parent[A]);
}
//自分のいるグループの頂点数を調べる
int size(int A)
{
return -Parent[root(A)]; //親をとってきたい]
}
bool issame(int x, int y)
{
return root(x) == root(y);
}
//AとBをくっ付ける
bool connect(int A, int B)
{
//AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
A = root(A);
B = root(B);
if (A == B)
{
//すでにくっついてるからくっ付けない
return false;
}
//大きい方(A)に小さいほう(B)をくっ付けたい
//大小が逆だったらひっくり返しちゃう。
if (size(A) < size(B))
swap(A, B);
//Aのサイズを更新する
Parent[A] += Parent[B];
//Bの親をAに変更する
Parent[B] = A;
return true;
}
};
long long fac[510000], finv[510000], inv[510000];
// テーブルを作る前処理
void COMinit()
{
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < 510000; i++)
{
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
// 二項係数計算
long long COM(int n, int k)
{
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
long long modinv(long long a, long long m)
{
long long b = m, u = 1, v = 0;
while (b)
{
long long t = a / b;
a -= t * b;
swap(a, b);
u -= t * v;
swap(u, v);
}
u %= m;
if (u < 0)
u += m;
return u;
}
void yn(bool flag)
{
if (flag)
{
cout << "Yes" << endl;
}
else
{
cout << "No" << endl;
}
return;
}
void YN(bool flag)
{
if (flag)
{
cout << "YES" << endl;
}
else
{
cout << "NO" << endl;
}
return;
}
std::vector<ll> enum_div(ll n) //nの約数を列挙
{
std::vector<ll> ret;
for (ll i = 1; i * i <= n; ++i)
{
if (n % i == 0)
{
ret.push_back(i);
if (i != 1 && i * i != n)
{
ret.push_back(n / i);
}
}
}
ret.push_back(n);
return ret;
}
// modint: mod 計算を int を扱うように扱える構造体
template <int MOD>
struct Fp
{
long long val;
constexpr Fp(long long v = 0) noexcept : val(v % MOD)
{
if (val < 0)
val += MOD;
}
constexpr int getmod() { return MOD; }
constexpr Fp operator-() const noexcept
{
return val ? MOD - val : 0;
}
constexpr Fp operator+(const Fp &r) const noexcept { return Fp(*this) += r; }
constexpr Fp operator-(const Fp &r) const noexcept { return Fp(*this) -= r; }
constexpr Fp operator*(const Fp &r) const noexcept { return Fp(*this) *= r; }
constexpr Fp operator/(const Fp &r) const noexcept { return Fp(*this) /= r; }
constexpr Fp &operator+=(const Fp &r) noexcept
{
val += r.val;
if (val >= MOD)
val -= MOD;
return *this;
}
constexpr Fp &operator-=(const Fp &r) noexcept
{
val -= r.val;
if (val < 0)
val += MOD;
return *this;
}
constexpr Fp &operator*=(const Fp &r) noexcept
{
val = val * r.val % MOD;
return *this;
}
constexpr Fp &operator/=(const Fp &r) noexcept
{
long long a = r.val, b = MOD, u = 1, v = 0;
while (b)
{
long long t = a / b;
a -= t * b;
swap(a, b);
u -= t * v;
swap(u, v);
}
val = val * u % MOD;
if (val < 0)
val += MOD;
return *this;
}
constexpr bool operator==(const Fp &r) const noexcept
{
return this->val == r.val;
}
constexpr bool operator!=(const Fp &r) const noexcept
{
return this->val != r.val;
}
friend constexpr ostream &operator<<(ostream &os, const Fp<MOD> &x) noexcept
{
return os << x.val;
}
friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept
{
if (n == 0)
return 1;
auto t = modpow(a, n / 2);
t = t * t;
if (n & 1)
t = t * a;
return t;
}
};
using mint = Fp<MOD>;
// グラフセット
struct Edge
{
ll to; // 辺の行き先
ll weight; // 辺の重み
Edge(int t, int w) : to(t), weight(w) {}
};
//using Graph = vector<vector<Edge>>;
#define def 0
template <class V, int NV>
struct SegTree
{ //[l,r)
V comp(V &l, V &r) { return max(l, r); };
vector<V> val;
SegTree() { val = vector<V>(NV * 2, def); }
V get(int x, int y, int l = 0, int r = NV, int k = 1)
{
if (r <= x || y <= l)
return def;
if (x <= l && r <= y)
return val[k];
auto a = get(x, y, l, (l + r) / 2, k * 2);
auto b = get(x, y, (l + r) / 2, r, k * 2 + 1);
return comp(a, b);
}
void update(int i, V v)
{
i += NV;
val[i] = v;
while (i > 1)
i >>= 1, val[i] = comp(val[i * 2], val[i * 2 + 1]);
}
void add(int i, V v) { update(i, val[i + NV] + v); }
V operator[](int x) { return get(x, x + 1); }
};
typedef vector<vector<long long>> matrix;
matrix mul_mod(matrix A, matrix B)
{
int H = A.size();
int W = B[0].size();
int K = A[0].size();
matrix C(H, vector<ll>(W, 0));
for (int i = 0; i < H; i++)
{
for (int j = 0; j < W; j++)
{
for (int k = 0; k < K; k++)
{
C[i][j] += A[i][k] * B[k][j];
C[i][j] %= MOD;
}
}
}
return C;
}
// 区間加算にも対応した BIT
template <class Abel>
struct BIT
{
vector<Abel> dat[2];
Abel UNITY_SUM = 0; // to be set
/* [1, n] */
BIT(int n) { init(n); }
void init(int n)
{
for (int iter = 0; iter < 2; ++iter)
dat[iter].assign(n + 1, UNITY_SUM);
}
/* a, b are 1-indexed, [a, b) */
inline void sub_add(int p, int a, Abel x)
{
for (int i = a; i < (int)dat[p].size(); i += i & -i)
dat[p][i] = dat[p][i] + x;
}
inline void add(int a, int b, Abel x)
{
sub_add(0, a, x * -(a - 1));
sub_add(1, a, x);
sub_add(0, b, x * (b - 1));
sub_add(1, b, x * (-1));
}
/* a is 1-indexed, [a, b) */
inline Abel sub_sum(int p, int a)
{
Abel res = UNITY_SUM;
for (int i = a; i > 0; i -= i & -i)
res = res + dat[p][i];
return res;
}
inline Abel sum(int a, int b)
{
return sub_sum(0, b - 1) + sub_sum(1, b - 1) * (b - 1) - sub_sum(0, a - 1) - sub_sum(1, a - 1) * (a - 1);
}
/* debug */
void print()
{
for (int i = 1; i < (int)dat[0].size(); ++i)
cout << sum(i, i + 1) << ",";
cout << endl;
}
};
using Graph = vector<vector<ll>>;
void print(const std::vector<int> &v)
{
std::for_each(v.begin(), v.end(), [](int x) {
std::cout << x << " ";
});
std::cout << std::endl;
}
const double PI = 3.14159265358979323846;
ll times_cap(ll a, ll b)
{
if (log10(a) + log10(b) >= 19.0)
return -1;
else
return a * b;
}
// konpairu command
// g++ code.cpp -std=c++14 -I .
//cout << std::setprecision(30) << ans << endl;
int main()
{
int n, d;
cin >> n;
vector<int> x(n), y(n);
for (int i = 0; i < n; i++)
{
cin >> x[i] >> y[i];
x[i]--;
y[i]--;
}
int left = 0, right = 1e9;
// ts[i] = (i-th flag is located on x[i])
while (right - left > 1)
{
int mid = left + (right - left) / 2; // 区間の真ん中
two_sat ts(n);
for (int i = 0; i < n; i++)
{
for (int j = i + 1; j < n; j++)
{
if (abs(x[i] - x[j]) < mid)
{
// cannot use both of x[i] and x[j]
ts.add_clause(i, false, j, false);
}
if (abs(x[i] - y[j]) < mid)
{
ts.add_clause(i, false, j, true);
}
if (abs(y[i] - x[j]) < mid)
{
ts.add_clause(i, true, j, false);
}
if (abs(y[i] - y[j]) < mid)
{
ts.add_clause(i, true, j, true);
}
}
}
/* 回答の応じて、年齢を絞る */
if (ts.satisfiable())
left = mid; // mid 歳以上なら、mid 歳以上 right 歳以下になるように
else
right = mid; // mid 歳未満なら、left 歳以上 mid 歳未満になるように
//cout << left << mid << right << endl;
}
cout << left << endl;
return 0;
} | a.cc:26:10: fatal error: atcoder/all: No such file or directory
26 | #include <atcoder/all>
| ^~~~~~~~~~~~~
compilation terminated.
|
s524322157 | p03802 | C++ | #ifndef ATCODER_INTERNAL_BITOP_HPP
#define ATCODER_INTERNAL_BITOP_HPP 1
#ifdef _MSC_VER
#include <intrin.h>
#endif
namespace atcoder {
namespace internal {
// @param n `0 <= n`
// @return minimum non-negative `x` s.t. `n <= 2**x`
int ceil_pow2(int n) {
int x = 0;
while ((1U << x) < (unsigned int)(n)) x++;
return x;
}
// @param n `1 <= n`
// @return minimum non-negative `x` s.t. `(n & (1 << x)) != 0`
int bsf(unsigned int n) {
#ifdef _MSC_VER
unsigned long index;
_BitScanForward(&index, n);
return index;
#else
return __builtin_ctz(n);
#endif
}
} // namespace internal
} // namespace atcoder
#endif // ATCODER_INTERNAL_BITOP_HPP
#ifndef ATCODER_INTERNAL_MATH_HPP
#define ATCODER_INTERNAL_MATH_HPP 1
#include <utility>
namespace atcoder {
namespace internal {
// @param m `1 <= m`
// @return x mod m
constexpr long long safe_mod(long long x, long long m) {
x %= m;
if (x < 0) x += m;
return x;
}
// Fast moduler by barrett reduction
// Reference: https://en.wikipedia.org/wiki/Barrett_reduction
// NOTE: reconsider after Ice Lake
struct barrett {
unsigned int _m;
unsigned long long im;
// @param m `1 <= m`
barrett(unsigned int m) : _m(m), im((unsigned long long)(-1) / m + 1) {}
// @return m
unsigned int umod() const { return _m; }
// @param a `0 <= a < m`
// @param b `0 <= b < m`
// @return `a * b % m`
unsigned int mul(unsigned int a, unsigned int b) const {
// [1] m = 1
// a = b = im = 0, so okay
// [2] m >= 2
// im = ceil(2^64 / m)
// -> im * m = 2^64 + r (0 <= r < m)
// let z = a*b = c*m + d (0 <= c, d < m)
// a*b * im = (c*m + d) * im = c*(im*m) + d*im = c*2^64 + c*r + d*im
// c*r + d*im < m * m + m * im < m * m + 2^64 + m <= 2^64 + m * (m + 1) < 2^64 * 2
// ((ab * im) >> 64) == c or c + 1
unsigned long long z = a;
z *= b;
#ifdef _MSC_VER
unsigned long long x;
_umul128(z, im, &x);
#else
unsigned long long x =
(unsigned long long)(((unsigned __int128)(z)*im) >> 64);
#endif
unsigned int v = (unsigned int)(z - x * _m);
if (_m <= v) v += _m;
return v;
}
};
// @param n `0 <= n`
// @param m `1 <= m`
// @return `(x ** n) % m`
constexpr long long pow_mod_constexpr(long long x, long long n, int m) {
if (m == 1) return 0;
unsigned int _m = (unsigned int)(m);
unsigned long long r = 1;
unsigned long long y = safe_mod(x, m);
while (n) {
if (n & 1) r = (r * y) % _m;
y = (y * y) % _m;
n >>= 1;
}
return r;
}
// Reference:
// M. Forisek and J. Jancina,
// Fast Primality Testing for Integers That Fit into a Machine Word
// @param n `0 <= n`
constexpr bool is_prime_constexpr(int n) {
if (n <= 1) return false;
if (n == 2 || n == 7 || n == 61) return true;
if (n % 2 == 0) return false;
long long d = n - 1;
while (d % 2 == 0) d /= 2;
for (long long a : {2, 7, 61}) {
long long t = d;
long long y = pow_mod_constexpr(a, t, n);
while (t != n - 1 && y != 1 && y != n - 1) {
y = y * y % n;
t <<= 1;
}
if (y != n - 1 && t % 2 == 0) {
return false;
}
}
return true;
}
template <int n> constexpr bool is_prime = is_prime_constexpr(n);
// @param b `1 <= b`
// @return pair(g, x) s.t. g = gcd(a, b), xa = g (mod b), 0 <= x < b/g
constexpr std::pair<long long, long long> inv_gcd(long long a, long long b) {
a = safe_mod(a, b);
if (a == 0) return {b, 0};
// Contracts:
// [1] s - m0 * a = 0 (mod b)
// [2] t - m1 * a = 0 (mod b)
// [3] s * |m1| + t * |m0| <= b
long long s = b, t = a;
long long m0 = 0, m1 = 1;
while (t) {
long long u = s / t;
s -= t * u;
m0 -= m1 * u; // |m1 * u| <= |m1| * s <= b
// [3]:
// (s - t * u) * |m1| + t * |m0 - m1 * u|
// <= s * |m1| - t * u * |m1| + t * (|m0| + |m1| * u)
// = s * |m1| + t * |m0| <= b
auto tmp = s;
s = t;
t = tmp;
tmp = m0;
m0 = m1;
m1 = tmp;
}
// by [3]: |m0| <= b/g
// by g != b: |m0| < b/g
if (m0 < 0) m0 += b / s;
return {s, m0};
}
// Compile time primitive root
// @param m must be prime
// @return primitive root (and minimum in now)
constexpr int primitive_root_constexpr(int m) {
if (m == 2) return 1;
if (m == 167772161) return 3;
if (m == 469762049) return 3;
if (m == 754974721) return 11;
if (m == 998244353) return 3;
int divs[20] = {};
divs[0] = 2;
int cnt = 1;
int x = (m - 1) / 2;
while (x % 2 == 0) x /= 2;
for (int i = 3; (long long)(i)*i <= x; i += 2) {
if (x % i == 0) {
divs[cnt++] = i;
while (x % i == 0) {
x /= i;
}
}
}
if (x > 1) {
divs[cnt++] = x;
}
for (int g = 2;; g++) {
bool ok = true;
for (int i = 0; i < cnt; i++) {
if (pow_mod_constexpr(g, (m - 1) / divs[i], m) == 1) {
ok = false;
break;
}
}
if (ok) return g;
}
}
template <int m> constexpr int primitive_root = primitive_root_constexpr(m);
} // namespace internal
} // namespace atcoder
#endif // ATCODER_INTERNAL_MATH_HPP
#ifndef ATCODER_INTERNAL_QUEUE_HPP
#define ATCODER_INTERNAL_QUEUE_HPP 1
#include <vector>
namespace atcoder {
namespace internal {
template <class T> struct simple_queue {
std::vector<T> payload;
int pos = 0;
void reserve(int n) { payload.reserve(n); }
int size() const { return int(payload.size()) - pos; }
bool empty() const { return pos == int(payload.size()); }
void push(const T& t) { payload.push_back(t); }
T& front() { return payload[pos]; }
void clear() {
payload.clear();
pos = 0;
}
void pop() { pos++; }
};
} // namespace internal
} // namespace atcoder
#endif // ATCODER_INTERNAL_QUEUE_HPP
#ifndef ATCODER_INTERNAL_SCC_HPP
#define ATCODER_INTERNAL_SCC_HPP 1
#include <algorithm>
#include <utility>
#include <vector>
namespace atcoder {
namespace internal {
template <class E> struct csr {
std::vector<int> start;
std::vector<E> elist;
csr(int n, const std::vector<std::pair<int, E>>& edges)
: start(n + 1), elist(edges.size()) {
for (auto e : edges) {
start[e.first + 1]++;
}
for (int i = 1; i <= n; i++) {
start[i] += start[i - 1];
}
auto counter = start;
for (auto e : edges) {
elist[counter[e.first]++] = e.second;
}
}
};
// Reference:
// R. Tarjan,
// Depth-First Search and Linear Graph Algorithms
struct scc_graph {
public:
scc_graph(int n) : _n(n) {}
int num_vertices() { return _n; }
void add_edge(int from, int to) { edges.push_back({from, {to}}); }
// @return pair of (# of scc, scc id)
std::pair<int, std::vector<int>> scc_ids() {
auto g = csr<edge>(_n, edges);
int now_ord = 0, group_num = 0;
std::vector<int> visited, low(_n), ord(_n, -1), ids(_n);
visited.reserve(_n);
auto dfs = [&](auto self, int v) -> void {
low[v] = ord[v] = now_ord++;
visited.push_back(v);
for (int i = g.start[v]; i < g.start[v + 1]; i++) {
auto to = g.elist[i].to;
if (ord[to] == -1) {
self(self, to);
low[v] = std::min(low[v], low[to]);
} else {
low[v] = std::min(low[v], ord[to]);
}
}
if (low[v] == ord[v]) {
while (true) {
int u = visited.back();
visited.pop_back();
ord[u] = _n;
ids[u] = group_num;
if (u == v) break;
}
group_num++;
}
};
for (int i = 0; i < _n; i++) {
if (ord[i] == -1) dfs(dfs, i);
}
for (auto& x : ids) {
x = group_num - 1 - x;
}
return {group_num, ids};
}
std::vector<std::vector<int>> scc() {
auto ids = scc_ids();
int group_num = ids.first;
std::vector<int> counts(group_num);
for (auto x : ids.second) counts[x]++;
std::vector<std::vector<int>> groups(ids.first);
for (int i = 0; i < group_num; i++) {
groups[i].reserve(counts[i]);
}
for (int i = 0; i < _n; i++) {
groups[ids.second[i]].push_back(i);
}
return groups;
}
private:
int _n;
struct edge {
int to;
};
std::vector<std::pair<int, edge>> edges;
};
} // namespace internal
} // namespace atcoder
#endif // ATCODER_INTERNAL_SCC_HPP
#ifndef ATCODER_INTERNAL_TYPE_TRAITS_HPP
#define ATCODER_INTERNAL_TYPE_TRAITS_HPP 1
#include <cassert>
#include <numeric>
#include <type_traits>
namespace atcoder {
namespace internal {
#ifndef _MSC_VER
template <class T>
using is_signed_int128 =
typename std::conditional<std::is_same<T, __int128_t>::value ||
std::is_same<T, __int128>::value,
std::true_type,
std::false_type>::type;
template <class T>
using is_unsigned_int128 =
typename std::conditional<std::is_same<T, __uint128_t>::value ||
std::is_same<T, unsigned __int128>::value,
std::true_type,
std::false_type>::type;
template <class T>
using make_unsigned_int128 =
typename std::conditional<std::is_same<T, __int128_t>::value,
__uint128_t,
unsigned __int128>;
template <class T>
using is_integral = typename std::conditional<std::is_integral<T>::value ||
is_signed_int128<T>::value ||
is_unsigned_int128<T>::value,
std::true_type,
std::false_type>::type;
template <class T>
using is_signed_int = typename std::conditional<(is_integral<T>::value &&
std::is_signed<T>::value) ||
is_signed_int128<T>::value,
std::true_type,
std::false_type>::type;
template <class T>
using is_unsigned_int =
typename std::conditional<(is_integral<T>::value &&
std::is_unsigned<T>::value) ||
is_unsigned_int128<T>::value,
std::true_type,
std::false_type>::type;
template <class T>
using to_unsigned = typename std::conditional<
is_signed_int128<T>::value,
make_unsigned_int128<T>,
typename std::conditional<std::is_signed<T>::value,
std::make_unsigned<T>,
std::common_type<T>>::type>::type;
#else
template <class T> using is_integral = typename std::is_integral<T>;
template <class T>
using is_signed_int =
typename std::conditional<is_integral<T>::value && std::is_signed<T>::value,
std::true_type,
std::false_type>::type;
template <class T>
using is_unsigned_int =
typename std::conditional<is_integral<T>::value &&
std::is_unsigned<T>::value,
std::true_type,
std::false_type>::type;
template <class T>
using to_unsigned = typename std::conditional<is_signed_int<T>::value,
std::make_unsigned<T>,
std::common_type<T>>::type;
#endif
template <class T>
using is_signed_int_t = std::enable_if_t<is_signed_int<T>::value>;
template <class T>
using is_unsigned_int_t = std::enable_if_t<is_unsigned_int<T>::value>;
template <class T> using to_unsigned_t = typename to_unsigned<T>::type;
} // namespace internal
} // namespace atcoder
#endif // ATCODER_INTERNAL_TYPE_TRAITS_HPP
#ifndef ATCODER_MODINT_HPP
#define ATCODER_MODINT_HPP 1
#include <cassert>
#include <numeric>
#include <type_traits>
#ifdef _MSC_VER
#include <intrin.h>
#endif
namespace atcoder {
namespace internal {
struct modint_base {};
struct static_modint_base : modint_base {};
template <class T> using is_modint = std::is_base_of<modint_base, T>;
template <class T> using is_modint_t = std::enable_if_t<is_modint<T>::value>;
} // namespace internal
template <int m, std::enable_if_t<(1 <= m)>* = nullptr>
struct static_modint : internal::static_modint_base {
using mint = static_modint;
public:
static constexpr int mod() { return m; }
static mint raw(int v) {
mint x;
x._v = v;
return x;
}
static_modint() : _v(0) {}
template <class T, internal::is_signed_int_t<T>* = nullptr>
static_modint(T v) {
long long x = (long long)(v % (long long)(umod()));
if (x < 0) x += umod();
_v = (unsigned int)(x);
}
template <class T, internal::is_unsigned_int_t<T>* = nullptr>
static_modint(T v) {
_v = (unsigned int)(v % umod());
}
static_modint(bool v) { _v = ((unsigned int)(v) % umod()); }
unsigned int val() const { return _v; }
mint& operator++() {
_v++;
if (_v == umod()) _v = 0;
return *this;
}
mint& operator--() {
if (_v == 0) _v = umod();
_v--;
return *this;
}
mint operator++(int) {
mint result = *this;
++*this;
return result;
}
mint operator--(int) {
mint result = *this;
--*this;
return result;
}
mint& operator+=(const mint& rhs) {
_v += rhs._v;
if (_v >= umod()) _v -= umod();
return *this;
}
mint& operator-=(const mint& rhs) {
_v -= rhs._v;
if (_v >= umod()) _v += umod();
return *this;
}
mint& operator*=(const mint& rhs) {
unsigned long long z = _v;
z *= rhs._v;
_v = (unsigned int)(z % umod());
return *this;
}
mint& operator/=(const mint& rhs) { return *this = *this * rhs.inv(); }
mint operator+() const { return *this; }
mint operator-() const { return mint() - *this; }
mint pow(long long n) const {
assert(0 <= n);
mint x = *this, r = 1;
while (n) {
if (n & 1) r *= x;
x *= x;
n >>= 1;
}
return r;
}
mint inv() const {
if (prime) {
assert(_v);
return pow(umod() - 2);
} else {
auto eg = internal::inv_gcd(_v, m);
assert(eg.first == 1);
return eg.second;
}
}
friend mint operator+(const mint& lhs, const mint& rhs) {
return mint(lhs) += rhs;
}
friend mint operator-(const mint& lhs, const mint& rhs) {
return mint(lhs) -= rhs;
}
friend mint operator*(const mint& lhs, const mint& rhs) {
return mint(lhs) *= rhs;
}
friend mint operator/(const mint& lhs, const mint& rhs) {
return mint(lhs) /= rhs;
}
friend bool operator==(const mint& lhs, const mint& rhs) {
return lhs._v == rhs._v;
}
friend bool operator!=(const mint& lhs, const mint& rhs) {
return lhs._v != rhs._v;
}
private:
unsigned int _v;
static constexpr unsigned int umod() { return m; }
static constexpr bool prime = internal::is_prime<m>;
};
template <int id> struct dynamic_modint : internal::modint_base {
using mint = dynamic_modint;
public:
static int mod() { return (int)(bt.umod()); }
static void set_mod(int m) {
assert(1 <= m);
bt = internal::barrett(m);
}
static mint raw(int v) {
mint x;
x._v = v;
return x;
}
dynamic_modint() : _v(0) {}
template <class T, internal::is_signed_int_t<T>* = nullptr>
dynamic_modint(T v) {
long long x = (long long)(v % (long long)(mod()));
if (x < 0) x += mod();
_v = (unsigned int)(x);
}
template <class T, internal::is_unsigned_int_t<T>* = nullptr>
dynamic_modint(T v) {
_v = (unsigned int)(v % mod());
}
dynamic_modint(bool v) { _v = ((unsigned int)(v) % mod()); }
unsigned int val() const { return _v; }
mint& operator++() {
_v++;
if (_v == umod()) _v = 0;
return *this;
}
mint& operator--() {
if (_v == 0) _v = umod();
_v--;
return *this;
}
mint operator++(int) {
mint result = *this;
++*this;
return result;
}
mint operator--(int) {
mint result = *this;
--*this;
return result;
}
mint& operator+=(const mint& rhs) {
_v += rhs._v;
if (_v >= umod()) _v -= umod();
return *this;
}
mint& operator-=(const mint& rhs) {
_v += mod() - rhs._v;
if (_v >= umod()) _v -= umod();
return *this;
}
mint& operator*=(const mint& rhs) {
_v = bt.mul(_v, rhs._v);
return *this;
}
mint& operator/=(const mint& rhs) { return *this = *this * rhs.inv(); }
mint operator+() const { return *this; }
mint operator-() const { return mint() - *this; }
mint pow(long long n) const {
assert(0 <= n);
mint x = *this, r = 1;
while (n) {
if (n & 1) r *= x;
x *= x;
n >>= 1;
}
return r;
}
mint inv() const {
auto eg = internal::inv_gcd(_v, mod());
assert(eg.first == 1);
return eg.second;
}
friend mint operator+(const mint& lhs, const mint& rhs) {
return mint(lhs) += rhs;
}
friend mint operator-(const mint& lhs, const mint& rhs) {
return mint(lhs) -= rhs;
}
friend mint operator*(const mint& lhs, const mint& rhs) {
return mint(lhs) *= rhs;
}
friend mint operator/(const mint& lhs, const mint& rhs) {
return mint(lhs) /= rhs;
}
friend bool operator==(const mint& lhs, const mint& rhs) {
return lhs._v == rhs._v;
}
friend bool operator!=(const mint& lhs, const mint& rhs) {
return lhs._v != rhs._v;
}
private:
unsigned int _v;
static internal::barrett bt;
static unsigned int umod() { return bt.umod(); }
};
template <int id> internal::barrett dynamic_modint<id>::bt = 998244353;
using modint998244353 = static_modint<998244353>;
using modint1000000007 = static_modint<1000000007>;
using modint = dynamic_modint<-1>;
namespace internal {
template <class T>
using is_static_modint = std::is_base_of<internal::static_modint_base, T>;
template <class T>
using is_static_modint_t = std::enable_if_t<is_static_modint<T>::value>;
template <class> struct is_dynamic_modint : public std::false_type {};
template <int id>
struct is_dynamic_modint<dynamic_modint<id>> : public std::true_type {};
template <class T>
using is_dynamic_modint_t = std::enable_if_t<is_dynamic_modint<T>::value>;
} // namespace internal
} // namespace atcoder
#endif // ATCODER_MODINT_HPP
#ifndef ATCODER_CONVOLUTION_HPP
#define ATCODER_CONVOLUTION_HPP 1
#include <algorithm>
#include <array>
#include <cassert>
#include <type_traits>
#include <vector>
namespace atcoder {
namespace internal {
template <class mint, internal::is_static_modint_t<mint>* = nullptr>
void butterfly(std::vector<mint>& a) {
static constexpr int g = internal::primitive_root<mint::mod()>;
int n = int(a.size());
int h = internal::ceil_pow2(n);
static bool first = true;
static mint sum_e[30]; // sum_e[i] = ies[0] * ... * ies[i - 1] * es[i]
if (first) {
first = false;
mint es[30], ies[30]; // es[i]^(2^(2+i)) == 1
int cnt2 = bsf(mint::mod() - 1);
mint e = mint(g).pow((mint::mod() - 1) >> cnt2), ie = e.inv();
for (int i = cnt2; i >= 2; i--) {
// e^(2^i) == 1
es[i - 2] = e;
ies[i - 2] = ie;
e *= e;
ie *= ie;
}
mint now = 1;
for (int i = 0; i < cnt2 - 2; i++) {
sum_e[i] = es[i] * now;
now *= ies[i];
}
}
for (int ph = 1; ph <= h; ph++) {
int w = 1 << (ph - 1), p = 1 << (h - ph);
mint now = 1;
for (int s = 0; s < w; s++) {
int offset = s << (h - ph + 1);
for (int i = 0; i < p; i++) {
auto l = a[i + offset];
auto r = a[i + offset + p] * now;
a[i + offset] = l + r;
a[i + offset + p] = l - r;
}
now *= sum_e[bsf(~(unsigned int)(s))];
}
}
}
template <class mint, internal::is_static_modint_t<mint>* = nullptr>
void butterfly_inv(std::vector<mint>& a) {
static constexpr int g = internal::primitive_root<mint::mod()>;
int n = int(a.size());
int h = internal::ceil_pow2(n);
static bool first = true;
static mint sum_ie[30]; // sum_ie[i] = es[0] * ... * es[i - 1] * ies[i]
if (first) {
first = false;
mint es[30], ies[30]; // es[i]^(2^(2+i)) == 1
int cnt2 = bsf(mint::mod() - 1);
mint e = mint(g).pow((mint::mod() - 1) >> cnt2), ie = e.inv();
for (int i = cnt2; i >= 2; i--) {
// e^(2^i) == 1
es[i - 2] = e;
ies[i - 2] = ie;
e *= e;
ie *= ie;
}
mint now = 1;
for (int i = 0; i < cnt2 - 2; i++) {
sum_ie[i] = ies[i] * now;
now *= es[i];
}
}
for (int ph = h; ph >= 1; ph--) {
int w = 1 << (ph - 1), p = 1 << (h - ph);
mint inow = 1;
for (int s = 0; s < w; s++) {
int offset = s << (h - ph + 1);
for (int i = 0; i < p; i++) {
auto l = a[i + offset];
auto r = a[i + offset + p];
a[i + offset] = l + r;
a[i + offset + p] =
(unsigned long long)(mint::mod() + l.val() - r.val()) *
inow.val();
}
inow *= sum_ie[bsf(~(unsigned int)(s))];
}
}
}
} // namespace internal
template <class mint, internal::is_static_modint_t<mint>* = nullptr>
std::vector<mint> convolution(std::vector<mint> a, std::vector<mint> b) {
int n = int(a.size()), m = int(b.size());
if (!n || !m) return {};
if (std::min(n, m) <= 60) {
if (n < m) {
std::swap(n, m);
std::swap(a, b);
}
std::vector<mint> ans(n + m - 1);
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
ans[i + j] += a[i] * b[j];
}
}
return ans;
}
int z = 1 << internal::ceil_pow2(n + m - 1);
a.resize(z);
internal::butterfly(a);
b.resize(z);
internal::butterfly(b);
for (int i = 0; i < z; i++) {
a[i] *= b[i];
}
internal::butterfly_inv(a);
a.resize(n + m - 1);
mint iz = mint(z).inv();
for (int i = 0; i < n + m - 1; i++) a[i] *= iz;
return a;
}
template <unsigned int mod = 998244353,
class T,
std::enable_if_t<internal::is_integral<T>::value>* = nullptr>
std::vector<T> convolution(const std::vector<T>& a, const std::vector<T>& b) {
int n = int(a.size()), m = int(b.size());
if (!n || !m) return {};
using mint = static_modint<mod>;
std::vector<mint> a2(n), b2(m);
for (int i = 0; i < n; i++) {
a2[i] = mint(a[i]);
}
for (int i = 0; i < m; i++) {
b2[i] = mint(b[i]);
}
auto c2 = convolution(move(a2), move(b2));
std::vector<T> c(n + m - 1);
for (int i = 0; i < n + m - 1; i++) {
c[i] = c2[i].val();
}
return c;
}
std::vector<long long> convolution_ll(const std::vector<long long>& a,
const std::vector<long long>& b) {
int n = int(a.size()), m = int(b.size());
if (!n || !m) return {};
static constexpr unsigned long long MOD1 = 754974721; // 2^24
static constexpr unsigned long long MOD2 = 167772161; // 2^25
static constexpr unsigned long long MOD3 = 469762049; // 2^26
static constexpr unsigned long long M2M3 = MOD2 * MOD3;
static constexpr unsigned long long M1M3 = MOD1 * MOD3;
static constexpr unsigned long long M1M2 = MOD1 * MOD2;
static constexpr unsigned long long M1M2M3 = MOD1 * MOD2 * MOD3;
static constexpr unsigned long long i1 =
internal::inv_gcd(MOD2 * MOD3, MOD1).second;
static constexpr unsigned long long i2 =
internal::inv_gcd(MOD1 * MOD3, MOD2).second;
static constexpr unsigned long long i3 =
internal::inv_gcd(MOD1 * MOD2, MOD3).second;
auto c1 = convolution<MOD1>(a, b);
auto c2 = convolution<MOD2>(a, b);
auto c3 = convolution<MOD3>(a, b);
std::vector<long long> c(n + m - 1);
for (int i = 0; i < n + m - 1; i++) {
unsigned long long x = 0;
x += (c1[i] * i1) % MOD1 * M2M3;
x += (c2[i] * i2) % MOD2 * M1M3;
x += (c3[i] * i3) % MOD3 * M1M2;
// B = 2^63, -B <= x, r(real value) < B
// (x, x - M, x - 2M, or x - 3M) = r (mod 2B)
// r = c1[i] (mod MOD1)
// focus on MOD1
// r = x, x - M', x - 2M', x - 3M' (M' = M % 2^64) (mod 2B)
// r = x,
// x - M' + (0 or 2B),
// x - 2M' + (0, 2B or 4B),
// x - 3M' + (0, 2B, 4B or 6B) (without mod!)
// (r - x) = 0, (0)
// - M' + (0 or 2B), (1)
// -2M' + (0 or 2B or 4B), (2)
// -3M' + (0 or 2B or 4B or 6B) (3) (mod MOD1)
// we checked that
// ((1) mod MOD1) mod 5 = 2
// ((2) mod MOD1) mod 5 = 3
// ((3) mod MOD1) mod 5 = 4
long long diff =
c1[i] - internal::safe_mod((long long)(x), (long long)(MOD1));
if (diff < 0) diff += MOD1;
static constexpr unsigned long long offset[5] = {
0, 0, M1M2M3, 2 * M1M2M3, 3 * M1M2M3};
x -= offset[diff % 5];
c[i] = x;
}
return c;
}
} // namespace atcoder
#endif // ATCODER_CONVOLUTION_HPP
#ifndef ATCODER_DSU_HPP
#define ATCODER_DSU_HPP 1
#include <algorithm>
#include <cassert>
#include <vector>
namespace atcoder {
// Implement (union by size) + (path compression)
// Reference:
// Zvi Galil and Giuseppe F. Italiano,
// Data structures and algorithms for disjoint set union problems
struct dsu {
public:
dsu() : _n(0) {}
dsu(int n) : _n(n), parent_or_size(n, -1) {}
int merge(int a, int b) {
assert(0 <= a && a < _n);
assert(0 <= b && b < _n);
int x = leader(a), y = leader(b);
if (x == y) return x;
if (-parent_or_size[x] < -parent_or_size[y]) std::swap(x, y);
parent_or_size[x] += parent_or_size[y];
parent_or_size[y] = x;
return x;
}
bool same(int a, int b) {
assert(0 <= a && a < _n);
assert(0 <= b && b < _n);
return leader(a) == leader(b);
}
int leader(int a) {
assert(0 <= a && a < _n);
if (parent_or_size[a] < 0) return a;
return parent_or_size[a] = leader(parent_or_size[a]);
}
int size(int a) {
assert(0 <= a && a < _n);
return -parent_or_size[leader(a)];
}
std::vector<std::vector<int>> groups() {
std::vector<int> leader_buf(_n), group_size(_n);
for (int i = 0; i < _n; i++) {
leader_buf[i] = leader(i);
group_size[leader_buf[i]]++;
}
std::vector<std::vector<int>> result(_n);
for (int i = 0; i < _n; i++) {
result[i].reserve(group_size[i]);
}
for (int i = 0; i < _n; i++) {
result[leader_buf[i]].push_back(i);
}
result.erase(
std::remove_if(result.begin(), result.end(),
[&](const std::vector<int>& v) { return v.empty(); }),
result.end());
return result;
}
private:
int _n;
// root node: -1 * component size
// otherwise: parent
std::vector<int> parent_or_size;
};
} // namespace atcoder
#endif // ATCODER_DSU_HPP
#ifndef ATCODER_FENWICKTREE_HPP
#define ATCODER_FENWICKTREE_HPP 1
#include <cassert>
#include <vector>
namespace atcoder {
// Reference: https://en.wikipedia.org/wiki/Fenwick_tree
template <class T> struct fenwick_tree {
using U = internal::to_unsigned_t<T>;
public:
fenwick_tree() : _n(0) {}
fenwick_tree(int n) : _n(n), data(n) {}
void add(int p, T x) {
assert(0 <= p && p < _n);
p++;
while (p <= _n) {
data[p - 1] += U(x);
p += p & -p;
}
}
T sum(int l, int r) {
assert(0 <= l && l <= r && r <= _n);
return sum(r) - sum(l);
}
private:
int _n;
std::vector<U> data;
U sum(int r) {
U s = 0;
while (r > 0) {
s += data[r - 1];
r -= r & -r;
}
return s;
}
};
} // namespace atcoder
#endif // ATCODER_FENWICKTREE_HPP
#ifndef ATCODER_LAZYSEGTREE_HPP
#define ATCODER_LAZYSEGTREE_HPP 1
#include <algorithm>
#include <cassert>
#include <iostream>
#include <vector>
namespace atcoder {
template <class S,
S (*op)(S, S),
S (*e)(),
class F,
S (*mapping)(F, S),
F (*composition)(F, F),
F (*id)()>
struct lazy_segtree {
public:
lazy_segtree() : lazy_segtree(0) {}
lazy_segtree(int n) : lazy_segtree(std::vector<S>(n, e())) {}
lazy_segtree(const std::vector<S>& v) : _n(int(v.size())) {
log = internal::ceil_pow2(_n);
size = 1 << log;
d = std::vector<S>(2 * size, e());
lz = std::vector<F>(size, id());
for (int i = 0; i < _n; i++) d[size + i] = v[i];
for (int i = size - 1; i >= 1; i--) {
update(i);
}
}
void set(int p, S x) {
assert(0 <= p && p < _n);
p += size;
for (int i = log; i >= 1; i--) push(p >> i);
d[p] = x;
for (int i = 1; i <= log; i++) update(p >> i);
}
S get(int p) {
assert(0 <= p && p < _n);
p += size;
for (int i = log; i >= 1; i--) push(p >> i);
return d[p];
}
S prod(int l, int r) {
assert(0 <= l && l <= r && r <= _n);
if (l == r) return e();
l += size;
r += size;
for (int i = log; i >= 1; i--) {
if (((l >> i) << i) != l) push(l >> i);
if (((r >> i) << i) != r) push(r >> i);
}
S sml = e(), smr = e();
while (l < r) {
if (l & 1) sml = op(sml, d[l++]);
if (r & 1) smr = op(d[--r], smr);
l >>= 1;
r >>= 1;
}
return op(sml, smr);
}
S all_prod() { return d[1]; }
void apply(int p, F f) {
assert(0 <= p && p < _n);
p += size;
for (int i = log; i >= 1; i--) push(p >> i);
d[p] = mapping(f, d[p]);
for (int i = 1; i <= log; i++) update(p >> i);
}
void apply(int l, int r, F f) {
assert(0 <= l && l <= r && r <= _n);
if (l == r) return;
l += size;
r += size;
for (int i = log; i >= 1; i--) {
if (((l >> i) << i) != l) push(l >> i);
if (((r >> i) << i) != r) push((r - 1) >> i);
}
{
int l2 = l, r2 = r;
while (l < r) {
if (l & 1) all_apply(l++, f);
if (r & 1) all_apply(--r, f);
l >>= 1;
r >>= 1;
}
l = l2;
r = r2;
}
for (int i = 1; i <= log; i++) {
if (((l >> i) << i) != l) update(l >> i);
if (((r >> i) << i) != r) update((r - 1) >> i);
}
}
template <bool (*g)(S)> int max_right(int l) {
return max_right(l, [](S x) { return g(x); });
}
template <class G> int max_right(int l, G g) {
assert(0 <= l && l <= _n);
assert(g(e()));
if (l == _n) return _n;
l += size;
for (int i = log; i >= 1; i--) push(l >> i);
S sm = e();
do {
while (l % 2 == 0) l >>= 1;
if (!g(op(sm, d[l]))) {
while (l < size) {
push(l);
l = (2 * l);
if (g(op(sm, d[l]))) {
sm = op(sm, d[l]);
l++;
}
}
return l - size;
}
sm = op(sm, d[l]);
l++;
} while ((l & -l) != l);
return _n;
}
template <bool (*g)(S)> int min_left(int r) {
return min_left(r, [](S x) { return g(x); });
}
template <class G> int min_left(int r, G g) {
assert(0 <= r && r <= _n);
assert(g(e()));
if (r == 0) return 0;
r += size;
for (int i = log; i >= 1; i--) push((r - 1) >> i);
S sm = e();
do {
r--;
while (r > 1 && (r % 2)) r >>= 1;
if (!g(op(d[r], sm))) {
while (r < size) {
push(r);
r = (2 * r + 1);
if (g(op(d[r], sm))) {
sm = op(d[r], sm);
r--;
}
}
return r + 1 - size;
}
sm = op(d[r], sm);
} while ((r & -r) != r);
return 0;
}
private:
int _n, size, log;
std::vector<S> d;
std::vector<F> lz;
void update(int k) { d[k] = op(d[2 * k], d[2 * k + 1]); }
void all_apply(int k, F f) {
d[k] = mapping(f, d[k]);
if (k < size) lz[k] = composition(f, lz[k]);
}
void push(int k) {
all_apply(2 * k, lz[k]);
all_apply(2 * k + 1, lz[k]);
lz[k] = id();
}
};
} // namespace atcoder
#endif // ATCODER_LAZYSEGTREE_HPP
#ifndef ATCODER_MATH_HPP
#define ATCODER_MATH_HPP 1
#include <algorithm>
#include <cassert>
#include <tuple>
#include <vector>
namespace atcoder {
long long pow_mod(long long x, long long n, int m) {
assert(0 <= n && 1 <= m);
if (m == 1) return 0;
internal::barrett bt((unsigned int)(m));
unsigned int r = 1, y = (unsigned int)(internal::safe_mod(x, m));
while (n) {
if (n & 1) r = bt.mul(r, y);
y = bt.mul(y, y);
n >>= 1;
}
return r;
}
long long inv_mod(long long x, long long m) {
assert(1 <= m);
auto z = internal::inv_gcd(x, m);
assert(z.first == 1);
return z.second;
}
// (rem, mod)
std::pair<long long, long long> crt(const std::vector<long long>& r,
const std::vector<long long>& m) {
assert(r.size() == m.size());
int n = int(r.size());
// Contracts: 0 <= r0 < m0
long long r0 = 0, m0 = 1;
for (int i = 0; i < n; i++) {
assert(1 <= m[i]);
long long r1 = internal::safe_mod(r[i], m[i]), m1 = m[i];
if (m0 < m1) {
std::swap(r0, r1);
std::swap(m0, m1);
}
if (m0 % m1 == 0) {
if (r0 % m1 != r1) return {0, 0};
continue;
}
// assume: m0 > m1, lcm(m0, m1) >= 2 * max(m0, m1)
// (r0, m0), (r1, m1) -> (r2, m2 = lcm(m0, m1));
// r2 % m0 = r0
// r2 % m1 = r1
// -> (r0 + x*m0) % m1 = r1
// -> x*u0*g % (u1*g) = (r1 - r0) (u0*g = m0, u1*g = m1)
// -> x = (r1 - r0) / g * inv(u0) (mod u1)
// im = inv(u0) (mod u1) (0 <= im < u1)
long long g, im;
std::tie(g, im) = internal::inv_gcd(m0, m1);
long long u1 = (m1 / g);
// |r1 - r0| < (m0 + m1) <= lcm(m0, m1)
if ((r1 - r0) % g) return {0, 0};
// u1 * u1 <= m1 * m1 / g / g <= m0 * m1 / g = lcm(m0, m1)
long long x = (r1 - r0) / g % u1 * im % u1;
// |r0| + |m0 * x|
// < m0 + m0 * (u1 - 1)
// = m0 + m0 * m1 / g - m0
// = lcm(m0, m1)
r0 += x * m0;
m0 *= u1; // -> lcm(m0, m1)
if (r0 < 0) r0 += m0;
}
return {r0, m0};
}
long long floor_sum(long long n, long long m, long long a, long long b) {
long long ans = 0;
if (a >= m) {
ans += (n - 1) * n * (a / m) / 2;
a %= m;
}
if (b >= m) {
ans += n * (b / m);
b %= m;
}
long long y_max = (a * n + b) / m, x_max = (y_max * m - b);
if (y_max == 0) return ans;
ans += (n - (x_max + a - 1) / a) * y_max;
ans += floor_sum(y_max, a, m, (a - x_max % a) % a);
return ans;
}
} // namespace atcoder
#endif // ATCODER_MATH_HPP
#ifndef ATCODER_MAXFLOW_HPP
#define ATCODER_MAXFLOW_HPP 1
#include <algorithm>
#include <cassert>
#include <limits>
#include <queue>
#include <vector>
namespace atcoder {
template <class Cap> struct mf_graph {
public:
mf_graph() : _n(0) {}
mf_graph(int n) : _n(n), g(n) {}
int add_edge(int from, int to, Cap cap) {
assert(0 <= from && from < _n);
assert(0 <= to && to < _n);
assert(0 <= cap);
int m = int(pos.size());
pos.push_back({from, int(g[from].size())});
g[from].push_back(_edge{to, int(g[to].size()), cap});
g[to].push_back(_edge{from, int(g[from].size()) - 1, 0});
return m;
}
struct edge {
int from, to;
Cap cap, flow;
};
edge get_edge(int i) {
int m = int(pos.size());
assert(0 <= i && i < m);
auto _e = g[pos[i].first][pos[i].second];
auto _re = g[_e.to][_e.rev];
return edge{pos[i].first, _e.to, _e.cap + _re.cap, _re.cap};
}
std::vector<edge> edges() {
int m = int(pos.size());
std::vector<edge> result;
for (int i = 0; i < m; i++) {
result.push_back(get_edge(i));
}
return result;
}
void change_edge(int i, Cap new_cap, Cap new_flow) {
int m = int(pos.size());
assert(0 <= i && i < m);
assert(0 <= new_flow && new_flow <= new_cap);
auto& _e = g[pos[i].first][pos[i].second];
auto& _re = g[_e.to][_e.rev];
_e.cap = new_cap - new_flow;
_re.cap = new_flow;
}
Cap flow(int s, int t) {
return flow(s, t, std::numeric_limits<Cap>::max());
}
Cap flow(int s, int t, Cap flow_limit) {
assert(0 <= s && s < _n);
assert(0 <= t && t < _n);
std::vector<int> level(_n), iter(_n);
internal::simple_queue<int> que;
auto bfs = [&]() {
std::fill(level.begin(), level.end(), -1);
level[s] = 0;
que.clear();
que.push(s);
while (!que.empty()) {
int v = que.front();
que.pop();
for (auto e : g[v]) {
if (e.cap == 0 || level[e.to] >= 0) continue;
level[e.to] = level[v] + 1;
if (e.to == t) return;
que.push(e.to);
}
}
};
auto dfs = [&](auto self, int v, Cap up) {
if (v == s) return up;
Cap res = 0;
int level_v = level[v];
for (int& i = iter[v]; i < int(g[v].size()); i++) {
_edge& e = g[v][i];
if (level_v <= level[e.to] || g[e.to][e.rev].cap == 0) continue;
Cap d =
self(self, e.to, std::min(up - res, g[e.to][e.rev].cap));
if (d <= 0) continue;
g[v][i].cap += d;
g[e.to][e.rev].cap -= d;
res += d;
if (res == up) break;
}
return res;
};
Cap flow = 0;
while (flow < flow_limit) {
bfs();
if (level[t] == -1) break;
std::fill(iter.begin(), iter.end(), 0);
while (flow < flow_limit) {
Cap f = dfs(dfs, t, flow_limit - flow);
if (!f) break;
flow += f;
}
}
return flow;
}
std::vector<bool> min_cut(int s) {
std::vector<bool> visited(_n);
internal::simple_queue<int> que;
que.push(s);
while (!que.empty()) {
int p = que.front();
que.pop();
visited[p] = true;
for (auto e : g[p]) {
if (e.cap && !visited[e.to]) {
visited[e.to] = true;
que.push(e.to);
}
}
}
return visited;
}
private:
int _n;
struct _edge {
int to, rev;
Cap cap;
};
std::vector<std::pair<int, int>> pos;
std::vector<std::vector<_edge>> g;
};
} // namespace atcoder
#endif // ATCODER_MAXFLOW_HPP
#ifndef ATCODER_MINCOSTFLOW_HPP
#define ATCODER_MINCOSTFLOW_HPP 1
#include <algorithm>
#include <cassert>
#include <limits>
#include <queue>
#include <vector>
namespace atcoder {
template <class Cap, class Cost> struct mcf_graph {
public:
mcf_graph() {}
mcf_graph(int n) : _n(n), g(n) {}
int add_edge(int from, int to, Cap cap, Cost cost) {
assert(0 <= from && from < _n);
assert(0 <= to && to < _n);
int m = int(pos.size());
pos.push_back({from, int(g[from].size())});
g[from].push_back(_edge{to, int(g[to].size()), cap, cost});
g[to].push_back(_edge{from, int(g[from].size()) - 1, 0, -cost});
return m;
}
struct edge {
int from, to;
Cap cap, flow;
Cost cost;
};
edge get_edge(int i) {
int m = int(pos.size());
assert(0 <= i && i < m);
auto _e = g[pos[i].first][pos[i].second];
auto _re = g[_e.to][_e.rev];
return edge{
pos[i].first, _e.to, _e.cap + _re.cap, _re.cap, _e.cost,
};
}
std::vector<edge> edges() {
int m = int(pos.size());
std::vector<edge> result(m);
for (int i = 0; i < m; i++) {
result[i] = get_edge(i);
}
return result;
}
std::pair<Cap, Cost> flow(int s, int t) {
return flow(s, t, std::numeric_limits<Cap>::max());
}
std::pair<Cap, Cost> flow(int s, int t, Cap flow_limit) {
return slope(s, t, flow_limit).back();
}
std::vector<std::pair<Cap, Cost>> slope(int s, int t) {
return slope(s, t, std::numeric_limits<Cap>::max());
}
std::vector<std::pair<Cap, Cost>> slope(int s, int t, Cap flow_limit) {
assert(0 <= s && s < _n);
assert(0 <= t && t < _n);
assert(s != t);
// variants (C = maxcost):
// -(n-1)C <= dual[s] <= dual[i] <= dual[t] = 0
// reduced cost (= e.cost + dual[e.from] - dual[e.to]) >= 0 for all edge
std::vector<Cost> dual(_n, 0), dist(_n);
std::vector<int> pv(_n), pe(_n);
std::vector<bool> vis(_n);
auto dual_ref = [&]() {
std::fill(dist.begin(), dist.end(),
std::numeric_limits<Cost>::max());
std::fill(pv.begin(), pv.end(), -1);
std::fill(pe.begin(), pe.end(), -1);
std::fill(vis.begin(), vis.end(), false);
struct Q {
Cost key;
int to;
bool operator<(Q r) const { return key > r.key; }
};
std::priority_queue<Q> que;
dist[s] = 0;
que.push(Q{0, s});
while (!que.empty()) {
int v = que.top().to;
que.pop();
if (vis[v]) continue;
vis[v] = true;
if (v == t) break;
// dist[v] = shortest(s, v) + dual[s] - dual[v]
// dist[v] >= 0 (all reduced cost are positive)
// dist[v] <= (n-1)C
for (int i = 0; i < int(g[v].size()); i++) {
auto e = g[v][i];
if (vis[e.to] || !e.cap) continue;
// |-dual[e.to] + dual[v]| <= (n-1)C
// cost <= C - -(n-1)C + 0 = nC
Cost cost = e.cost - dual[e.to] + dual[v];
if (dist[e.to] - dist[v] > cost) {
dist[e.to] = dist[v] + cost;
pv[e.to] = v;
pe[e.to] = i;
que.push(Q{dist[e.to], e.to});
}
}
}
if (!vis[t]) {
return false;
}
for (int v = 0; v < _n; v++) {
if (!vis[v]) continue;
// dual[v] = dual[v] - dist[t] + dist[v]
// = dual[v] - (shortest(s, t) + dual[s] - dual[t]) + (shortest(s, v) + dual[s] - dual[v])
// = - shortest(s, t) + dual[t] + shortest(s, v)
// = shortest(s, v) - shortest(s, t) >= 0 - (n-1)C
dual[v] -= dist[t] - dist[v];
}
return true;
};
Cap flow = 0;
Cost cost = 0, prev_cost = -1;
std::vector<std::pair<Cap, Cost>> result;
result.push_back({flow, cost});
while (flow < flow_limit) {
if (!dual_ref()) break;
Cap c = flow_limit - flow;
for (int v = t; v != s; v = pv[v]) {
c = std::min(c, g[pv[v]][pe[v]].cap);
}
for (int v = t; v != s; v = pv[v]) {
auto& e = g[pv[v]][pe[v]];
e.cap -= c;
g[v][e.rev].cap += c;
}
Cost d = -dual[s];
flow += c;
cost += c * d;
if (prev_cost == d) {
result.pop_back();
}
result.push_back({flow, cost});
prev_cost = cost;
}
return result;
}
private:
int _n;
struct _edge {
int to, rev;
Cap cap;
Cost cost;
};
std::vector<std::pair<int, int>> pos;
std::vector<std::vector<_edge>> g;
};
} // namespace atcoder
#endif // ATCODER_MINCOSTFLOW_HPP
#ifndef ATCODER_SCC_HPP
#define ATCODER_SCC_HPP 1
#include <algorithm>
#include <cassert>
#include <vector>
namespace atcoder {
struct scc_graph {
public:
scc_graph() : internal(0) {}
scc_graph(int n) : internal(n) {}
void add_edge(int from, int to) {
int n = internal.num_vertices();
assert(0 <= from && from < n);
assert(0 <= to && to < n);
internal.add_edge(from, to);
}
std::vector<std::vector<int>> scc() { return internal.scc(); }
private:
internal::scc_graph internal;
};
} // namespace atcoder
#endif // ATCODER_SCC_HPP
#ifndef ATCODER_SEGTREE_HPP
#define ATCODER_SEGTREE_HPP 1
#include <algorithm>
#include <cassert>
#include <vector>
namespace atcoder {
template <class S, S (*op)(S, S), S (*e)()> struct segtree {
public:
segtree() : segtree(0) {}
segtree(int n) : segtree(std::vector<S>(n, e())) {}
segtree(const std::vector<S>& v) : _n(int(v.size())) {
log = internal::ceil_pow2(_n);
size = 1 << log;
d = std::vector<S>(2 * size, e());
for (int i = 0; i < _n; i++) d[size + i] = v[i];
for (int i = size - 1; i >= 1; i--) {
update(i);
}
}
void set(int p, S x) {
assert(0 <= p && p < _n);
p += size;
d[p] = x;
for (int i = 1; i <= log; i++) update(p >> i);
}
S get(int p) {
assert(0 <= p && p < _n);
return d[p + size];
}
S prod(int l, int r) {
assert(0 <= l && l <= r && r <= _n);
S sml = e(), smr = e();
l += size;
r += size;
while (l < r) {
if (l & 1) sml = op(sml, d[l++]);
if (r & 1) smr = op(d[--r], smr);
l >>= 1;
r >>= 1;
}
return op(sml, smr);
}
S all_prod() { return d[1]; }
template <bool (*f)(S)> int max_right(int l) {
return max_right(l, [](S x) { return f(x); });
}
template <class F> int max_right(int l, F f) {
assert(0 <= l && l <= _n);
assert(f(e()));
if (l == _n) return _n;
l += size;
S sm = e();
do {
while (l % 2 == 0) l >>= 1;
if (!f(op(sm, d[l]))) {
while (l < size) {
l = (2 * l);
if (f(op(sm, d[l]))) {
sm = op(sm, d[l]);
l++;
}
}
return l - size;
}
sm = op(sm, d[l]);
l++;
} while ((l & -l) != l);
return _n;
}
template <bool (*f)(S)> int min_left(int r) {
return min_left(r, [](S x) { return f(x); });
}
template <class F> int min_left(int r, F f) {
assert(0 <= r && r <= _n);
assert(f(e()));
if (r == 0) return 0;
r += size;
S sm = e();
do {
r--;
while (r > 1 && (r % 2)) r >>= 1;
if (!f(op(d[r], sm))) {
while (r < size) {
r = (2 * r + 1);
if (f(op(d[r], sm))) {
sm = op(d[r], sm);
r--;
}
}
return r + 1 - size;
}
sm = op(d[r], sm);
} while ((r & -r) != r);
return 0;
}
private:
int _n, size, log;
std::vector<S> d;
void update(int k) { d[k] = op(d[2 * k], d[2 * k + 1]); }
};
} // namespace atcoder
#endif // ATCODER_SEGTREE_HPP
#ifndef ATCODER_STRING_HPP
#define ATCODER_STRING_HPP 1
#include <algorithm>
#include <cassert>
#include <numeric>
#include <string>
#include <vector>
namespace atcoder {
namespace internal {
std::vector<int> sa_naive(const std::vector<int>& s) {
int n = int(s.size());
std::vector<int> sa(n);
std::iota(sa.begin(), sa.end(), 0);
std::sort(sa.begin(), sa.end(), [&](int l, int r) {
if (l == r) return false;
while (l < n && r < n) {
if (s[l] != s[r]) return s[l] < s[r];
l++;
r++;
}
return l == n;
});
return sa;
}
std::vector<int> sa_doubling(const std::vector<int>& s) {
int n = int(s.size());
std::vector<int> sa(n), rnk = s, tmp(n);
std::iota(sa.begin(), sa.end(), 0);
for (int k = 1; k < n; k *= 2) {
auto cmp = [&](int x, int y) {
if (rnk[x] != rnk[y]) return rnk[x] < rnk[y];
int rx = x + k < n ? rnk[x + k] : -1;
int ry = y + k < n ? rnk[y + k] : -1;
return rx < ry;
};
std::sort(sa.begin(), sa.end(), cmp);
tmp[sa[0]] = 0;
for (int i = 1; i < n; i++) {
tmp[sa[i]] = tmp[sa[i - 1]] + (cmp(sa[i - 1], sa[i]) ? 1 : 0);
}
std::swap(tmp, rnk);
}
return sa;
}
// SA-IS, linear-time suffix array construction
// Reference:
// G. Nong, S. Zhang, and W. H. Chan,
// Two Efficient Algorithms for Linear Time Suffix Array Construction
template <int THRESHOLD_NAIVE = 10, int THRESHOLD_DOUBLING = 40>
std::vector<int> sa_is(const std::vector<int>& s, int upper) {
int n = int(s.size());
if (n == 0) return {};
if (n == 1) return {0};
if (n == 2) {
if (s[0] < s[1]) {
return {0, 1};
} else {
return {1, 0};
}
}
if (n < THRESHOLD_NAIVE) {
return sa_naive(s);
}
if (n < THRESHOLD_DOUBLING) {
return sa_doubling(s);
}
std::vector<int> sa(n);
std::vector<bool> ls(n);
for (int i = n - 2; i >= 0; i--) {
ls[i] = (s[i] == s[i + 1]) ? ls[i + 1] : (s[i] < s[i + 1]);
}
std::vector<int> sum_l(upper + 1), sum_s(upper + 1);
for (int i = 0; i < n; i++) {
if (!ls[i]) {
sum_s[s[i]]++;
} else {
sum_l[s[i] + 1]++;
}
}
for (int i = 0; i <= upper; i++) {
sum_s[i] += sum_l[i];
if (i < upper) sum_l[i + 1] += sum_s[i];
}
auto induce = [&](const std::vector<int>& lms) {
std::fill(sa.begin(), sa.end(), -1);
std::vector<int> buf(upper + 1);
std::copy(sum_s.begin(), sum_s.end(), buf.begin());
for (auto d : lms) {
if (d == n) continue;
sa[buf[s[d]]++] = d;
}
std::copy(sum_l.begin(), sum_l.end(), buf.begin());
sa[buf[s[n - 1]]++] = n - 1;
for (int i = 0; i < n; i++) {
int v = sa[i];
if (v >= 1 && !ls[v - 1]) {
sa[buf[s[v - 1]]++] = v - 1;
}
}
std::copy(sum_l.begin(), sum_l.end(), buf.begin());
for (int i = n - 1; i >= 0; i--) {
int v = sa[i];
if (v >= 1 && ls[v - 1]) {
sa[--buf[s[v - 1] + 1]] = v - 1;
}
}
};
std::vector<int> lms_map(n + 1, -1);
int m = 0;
for (int i = 1; i < n; i++) {
if (!ls[i - 1] && ls[i]) {
lms_map[i] = m++;
}
}
std::vector<int> lms;
lms.reserve(m);
for (int i = 1; i < n; i++) {
if (!ls[i - 1] && ls[i]) {
lms.push_back(i);
}
}
induce(lms);
if (m) {
std::vector<int> sorted_lms;
sorted_lms.reserve(m);
for (int v : sa) {
if (lms_map[v] != -1) sorted_lms.push_back(v);
}
std::vector<int> rec_s(m);
int rec_upper = 0;
rec_s[lms_map[sorted_lms[0]]] = 0;
for (int i = 1; i < m; i++) {
int l = sorted_lms[i - 1], r = sorted_lms[i];
int end_l = (lms_map[l] + 1 < m) ? lms[lms_map[l] + 1] : n;
int end_r = (lms_map[r] + 1 < m) ? lms[lms_map[r] + 1] : n;
bool same = true;
if (end_l - l != end_r - r) {
same = false;
} else {
while (l < end_l) {
if (s[l] != s[r]) {
break;
}
l++;
r++;
}
if (l == n || s[l] != s[r]) same = false;
}
if (!same) rec_upper++;
rec_s[lms_map[sorted_lms[i]]] = rec_upper;
}
auto rec_sa =
sa_is<THRESHOLD_NAIVE, THRESHOLD_DOUBLING>(rec_s, rec_upper);
for (int i = 0; i < m; i++) {
sorted_lms[i] = lms[rec_sa[i]];
}
induce(sorted_lms);
}
return sa;
}
} // namespace internal
std::vector<int> suffix_array(const std::vector<int>& s, int upper) {
assert(0 <= upper);
for (int d : s) {
assert(0 <= d && d <= upper);
}
auto sa = internal::sa_is(s, upper);
return sa;
}
template <class T> std::vector<int> suffix_array(const std::vector<T>& s) {
int n = int(s.size());
std::vector<int> idx(n);
iota(idx.begin(), idx.end(), 0);
sort(idx.begin(), idx.end(), [&](int l, int r) { return s[l] < s[r]; });
std::vector<int> s2(n);
int now = 0;
for (int i = 0; i < n; i++) {
if (i && s[idx[i - 1]] != s[idx[i]]) now++;
s2[idx[i]] = now;
}
return internal::sa_is(s2, now);
}
std::vector<int> suffix_array(const std::string& s) {
int n = int(s.size());
std::vector<int> s2(n);
for (int i = 0; i < n; i++) {
s2[i] = s[i];
}
return internal::sa_is(s2, 255);
}
// Reference:
// T. Kasai, G. Lee, H. Arimura, S. Arikawa, and K. Park,
// Linear-Time Longest-Common-Prefix Computation in Suffix Arrays and Its
// Applications
template <class T>
std::vector<int> lcp_array(const std::vector<T>& s,
const std::vector<int>& sa) {
int n = int(s.size());
assert(n >= 1);
std::vector<int> rnk(n);
for (int i = 0; i < n; i++) {
rnk[sa[i]] = i;
}
std::vector<int> lcp(n - 1);
int h = 0;
for (int i = 0; i < n; i++) {
if (h > 0) h--;
if (rnk[i] == 0) continue;
int j = sa[rnk[i] - 1];
for (; j + h < n && i + h < n; h++) {
if (s[j + h] != s[i + h]) break;
}
lcp[rnk[i] - 1] = h;
}
return lcp;
}
std::vector<int> lcp_array(const std::string& s, const std::vector<int>& sa) {
int n = int(s.size());
std::vector<int> s2(n);
for (int i = 0; i < n; i++) {
s2[i] = s[i];
}
return lcp_array(s2, sa);
}
// Reference:
// D. Gusfield,
// Algorithms on Strings, Trees, and Sequences: Computer Science and
// Computational Biology
template <class T> std::vector<int> z_algorithm(const std::vector<T>& s) {
int n = int(s.size());
if (n == 0) return {};
std::vector<int> z(n);
z[0] = 0;
for (int i = 1, j = 0; i < n; i++) {
int& k = z[i];
k = (j + z[j] <= i) ? 0 : std::min(j + z[j] - i, z[i - j]);
while (i + k < n && s[k] == s[i + k]) k++;
if (j + z[j] < i + z[i]) j = i;
}
z[0] = n;
return z;
}
std::vector<int> z_algorithm(const std::string& s) {
int n = int(s.size());
std::vector<int> s2(n);
for (int i = 0; i < n; i++) {
s2[i] = s[i];
}
return z_algorithm(s2);
}
} // namespace atcoder
#endif // ATCODER_STRING_HPP
#ifndef ATCODER_TWOSAT_HPP
#define ATCODER_TWOSAT_HPP 1
#include <cassert>
#include <vector>
namespace atcoder {
// Reference:
// B. Aspvall, M. Plass, and R. Tarjan,
// A Linear-Time Algorithm for Testing the Truth of Certain Quantified Boolean
// Formulas
struct two_sat {
public:
two_sat() : _n(0), scc(0) {}
two_sat(int n) : _n(n), _answer(n), scc(2 * n) {}
void add_clause(int i, bool f, int j, bool g) {
assert(0 <= i && i < _n);
assert(0 <= j && j < _n);
scc.add_edge(2 * i + (f ? 0 : 1), 2 * j + (g ? 1 : 0));
scc.add_edge(2 * j + (g ? 0 : 1), 2 * i + (f ? 1 : 0));
}
bool satisfiable() {
auto id = scc.scc_ids().second;
for (int i = 0; i < _n; i++) {
if (id[2 * i] == id[2 * i + 1]) return false;
_answer[i] = id[2 * i] < id[2 * i + 1];
}
return true;
}
std::vector<bool> answer() { return _answer; }
private:
int _n;
std::vector<bool> _answer;
internal::scc_graph scc;
};
} // namespace atcoder
#endif // ATCODER_TWOSAT_HPP
#include <bits/stdc++.h>
#include <atcoder/all>
#define int long long
#define sint signed
#define endl "\n" // fflush(stdout);
#define ALL(v) (v).begin(),(v).end()
#define Vi vector<int>
#define VVi vector<Vi>
#define VVVi vector<VVi>
#define Vm vector<mint>
#define Vs vector<string>
#define Vd vector<double>
#define Vc vector<char>
#define Pii pair<int,int>
#define Pdd pair<double,double>
#define VPii vector<Pii>
#define Tiii tuple<int,int,int>
#define VTiii vector<Tiii>
#define PQi priority_queue<int>
#define PQir priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define itos to_string
#define stoi stoll
#define FI first
#define SE second
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define cyes cout<<"yes"<<endl
#define cno cout<<"no"<<endl
#define sortr(v) sort(v,greater<>())
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repeq(i,a,b) for(int i=a;i<=b;i++)
#define repreq(i,a,b) for(int i=a;i>=b;i--)
#define dem(a,b) ((a+b-1)/(b))
#define INF 3000000000000000000 // 3.0*10^18
#define MAX LLONG_MAX
#define PI acos(-1.0L)
const int MOD = 998244353; // case
//const int MOD = 1000000007; // 10^9 + 7
const double EPS = 1e-6;
using namespace std;
using namespace atcoder;
/* debug */
template <typename T> // vector
ostream& operator<<(ostream& os,const vector<T> &V){int N=V.size();
if(N==0){os<<'.';return os;}rep(i,0,N-1){os<<V[i]<<' ';}os<<V[N-1];return os;}
template <typename T> // vector vector
ostream& operator<<(ostream& os,const vector<vector<T>> &V){
int N=V.size();rep(i,0,N-1)cout<<V[i]<<endl;cout<<V[N-1];return os;}
template <typename T,typename S> // pair
ostream& operator<<(ostream& os, pair<T,S> const&P){os<<P.FI<<' '<<P.SE;return os;}
template <typename T> // set
ostream& operator<<(ostream& os,set<T> &S){auto it=S.begin();while(it!=S.end()){
os<<*it;if(next(it,1)!=S.end())os<<' ';it++;};return os;}
template <typename T> // deque
ostream& operator<<(ostream& os, deque<T> &q){for(auto it=q.begin();it<q.end();it++){
os<<*it;if(it+1!=q.end())os<<" ";}return os;}
/* useful */
template<typename T>void Vin(vector<T> &v){int n=v.size();rep(i,0,n)cin>>v[i];}
int scomb(int n, int r){if(r<0||r>n)return 0;if((n-r)<r)r=n-r; // nCr
int a=1;for(int i=n;i>n-r;--i){a=a*i;}for(int i=1;i<r+1;++i){a=a/i;}return a;}
Vi vis(Vi &v){Vi S(v.size()+1);rep(i,1,S.size())S[i]+=v[i-1]+S[i-1];return S;}
int digit_sum(int n){int ret=0; while(n>0){ret+=n%10;n/=10;}return ret;}
int digit(int k,int i){string s = itos(k);return s[s.size()-i]-'0';} // i桁目の数字
template<typename T>void press(T &v){v.erase(unique(ALL(v)),v.end());} // 圧縮
Vi zip(Vi b){int Z=b.size(); // 座標圧縮
Pii p[Z+10];int a=b.size();Vi l(a);for(int i=0;i<a;i++)
p[i]=mp(b[i],i);sort(p,p+a);int w=0;for(int i=0;i<a;i++)
{if(i&&p[i].first!=p[i-1].first)w++;l[p[i].second]=w;}return l;}
int modiv(int a,int b){return a*pow_mod(b,MOD-2,MOD)%MOD;} // a÷b(%MOD)
int SMALLER(Vi &a,int x){return lower_bound(a.begin(),a.end(),x)-a.begin();}
int orSMALLER(Vi &a,int x){return upper_bound(a.begin(),a.end(),x)-a.begin();}
int BIGGER(Vi &a,int x){return a.size()-orSMALLER(a,x);}
int orBIGGER(Vi &a,int x){return a.size()-SMALLER(a,x);}
int COUNT(Vi &a,int x) {return upper_bound(ALL(a),x)-lower_bound(ALL(a),x);}
int maxind(Vi &a){return max_element(ALL(a))-a.begin();}
int minind(Vi &a){return min_element(ALL(a))-a.begin();}
Vi nibe2V(){Vi a(60);int q = 1;rep(i,0,60){a[i]=q;q*=2;}return a;}
//Vi nibe = nibe2V(); // 2^n
Vi stpowV(){Vi a(1000005);a[0]=1;repeq(i,1,1000004)a[i]=a[i-1]*i%MOD;return a;}
//Vi stpow = stpowV(); // 階乗配列(%MOD)
using mint = static_modint<MOD>;
/****************************** START ******************************/
int n;
Vi x,y;
bool check(int mid){ // ([...,0,0,0,"1",1,1,...])
two_sat ts(n);
rep(i,0,n)rep(j,i+1,n){
if(abs(x[i]-x[j]) < mid) ts.add_clause(i,0,j,0);
if(abs(x[i]-y[j]) < mid) ts.add_clause(i,0,j,1);
if(abs(y[i]-x[j]) < mid) ts.add_clause(i,1,j,0);
if(abs(y[i]-y[j]) < mid) ts.add_clause(i,1,j,1);
}
if(ts.satisfiable()) return 0;
else return 1;
}
int binary(){
int L = 0,R = 1000000010; // [L,R]の範囲内に解
int mid = (L+R)/2;
while(L<R){
if(check(mid)) {
R = mid;
}
else {
L = mid+1;
}
mid = (L+R)/2;
}
return mid-1;
}
signed main() {
cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(12);
cin >> n;
x = Vi(n);
y = x;
rep(i,0,n) cin >> x[i] >> y[i];
cout << binary() << endl;
return 0;
} | a.cc:1864:10: fatal error: atcoder/all: No such file or directory
1864 | #include <atcoder/all>
| ^~~~~~~~~~~~~
compilation terminated.
|
s578582945 | p03802 | C++ | //Be Name Khoda, Besmellah Rahmane Rahim, In The Name Of God;
//#include<bits/stdc++.h>
#include<iostream>
#include <vector>
#include <algorithm>
#include <cntath>
#include <set>
#include <queue>
#include <deque>
#include <map>
#include <stack>
#include<bitset>
#include<list>
#include<cassert>
#include<numeric>
#include <stdio.h>
#include <string.h>
#include<iomanip>
#include<unordered_map>
#include<unordered_set>
#include <fstream>
using namespace std;
const int N = 20000 + 5;
const int inf = 1e9 + 7;
int n;
int X[N];
int ind[N];
int out[N << 2];
int in[N << 2];
int pnt;
int color[N];
vector<int> graph[N * 20], rgraph[N * 20], topol;
int mark[N * 20];
bool cmp(int x, int y)
{
return X[x] < X[y];
}
int Not(int a)
{
if(a > 2 * n)
{
a -= 2 * n;
}
else
{
a += 2 * n;
}
return a;
}
void build(int v, int l, int r)
{
if (r - l == 1)
{
out[v] = ++pnt;
graph[out[v]].push_back(Not(ind[l]));
rgraph[Not(ind[l])].push_back(out[v]);
in[v] = ++pnt;
graph[ind[l]].push_back(in[v]);
rgraph[in[v]].push_back(ind[l]);
return;
}
int mid = (l + r) >> 1;
build(v << 1, l, mid);
build(v << 1 | 1, mid, r);
out[v] = ++pnt;
graph[out[v]].push_back(out[v << 1]);
graph[out[v]].push_back(out[v << 1 | 1]);
rgraph[out[v << 1]].push_back(out[v]);
rgraph[out[v << 1 | 1]].push_back(out[v]);
in[v] = ++pnt;
graph[in[v << 1]].push_back(in[v]);
graph[in[v << 1 | 1]].push_back(in[v]);
rgraph[in[v]].push_back(in[v << 1]);
rgraph[in[v]].push_back(in[v << 1 | 1]);
}
void dfs(int v)
{
mark[v] = 1;
for (auto u: graph[v])
{
if (!mark[u])
{
dfs(u);
}
}
topol.push_back(v);
}
void sfd(int v, int c)
{
mark[v] = 1;
color[v] = c;
for (auto u:rgraph[v])
{
if (!mark[u])
sfd(u, c);
}
}
void add(int v, int lq, int rq, bool f, int x, int l, int r)
{
if (rq <= l || r <= lq)
{
return;
}
if (lq <= l && r <= rq)
{
if (f == 0)
{
graph[x].push_back(out[v]), rgraph[out[v]].push_back(x);
}
else
{
graph[in[v]].push_back(x);
rgraph[x].push_back(in[v]);
}
return;
}
int mid = (l + r) >> 1;
add(v << 1, lq, rq, f, x, l, mid);
add(v << 1 | 1, lq, rq, f, x, mid, r);
}
void add_clause(int x, int y)
{
graph[Not(x)].push_back(y);
rgraph[y].push_back(Not(x));
graph[Not(y)].push_back(x);
rgraph[x].push_back(Not(y));
}
bool isVal(int x)
{
pnt = 4 * n;
memset(mark, 0, sizeof mark);
for (int i = 0; i < N * 20; i++)
{
graph[i].clear();
rgraph[i].clear();
}
topol.clear();
build(1, 1, 2 * n + 1);
for (int i = 1; i <= n; i++)
{
int L = 2 * i - 1;
int R = 2 * i;
add_clause(Not(L), Not(R));
add_clause(L, R);
}
X[0] = -inf;
X[2 * n + 1] = inf;
for (int i = 1; i <= 2 * n; i++)
{
int l = 0, r = i;
while (r - l > 1)
{
int mid = (l + r) / 2;
if (abs(X[ind[mid]] - X[ind[i]]) < x)
{
r = mid;
}
else
{
l = mid;
}
}
if (r != i)
{
add(1, r, i, 0, ind[i], 1, 2 * n + 1);
add(1, r, i, 1, Not(ind[i]), 1, 2 * n + 1);
}
l = i, r = 2 * n + 1;
while (r - l > 1)
{
int mid = (l + r) >> 1;
if (abs(X[ind[mid]] - X[ind[i]]) < x)
{
l = mid;
}
else
{
r = mid;
}
}
if (l != i)
{
add(1, i + 1, l + 1, 0, ind[i], 1, 2 * n + 1);
add(1, i + 1, l + 1, 1, Not(ind[i]), 1, 2 * n + 1);
}
}
for (int i = 1; i <= pnt; i++)
{
if (!mark[i])
{
dfs(i);
}
}
reverse(topol.begin(), topol.end());
memset(mark, 0, sizeof mark);
int cnt = 0;
for (auto u:topol)
{
if (!mark[u])
{
sfd(u, ++cnt);
}
}
for (int i = 1; i <= 2 * n; i++)
{
if (color[i] == color[i + 2 * n])
{
return 0;
}
}
return 1;
}
void bsearch()
{
int l = -1;
int r = inf;
while (r - l > 1)
{
int mid = (l + r) >> 1;
if (isVal(mid))
{
l = mid;
}
else
{
r = mid;
}
}
cout << l;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n;
for (int i = 1; i <= 2 * n; i++)
{
cin >> X[i];
ind[i] = i;
}
sort(ind + 1, ind + 2 * n + 1, cmp);
bsearch();
}
| a.cc:6:10: fatal error: cntath: No such file or directory
6 | #include <cntath>
| ^~~~~~~~
compilation terminated.
|
s096404988 | p03802 | C++ | #include <bits/stdc++.h>
using namespace std;
#define N 10005
int n,m,rt,g,cnt,tot,nm,I,tp,x[N][2],y[N][2],id[N*10],he[N*10],ne[N*10],to[N*10],dfn[N*10],low[N*10],sc[N*10],in[N*10],st[N*10];vector<int>s[N*2];
struct nod{int x,d;friend int operator<(nod a,nod b){if(a.x!=b.x) return a.x<b.x;return a.d<b.d;}}t[N*2];
void add(int x,int y){to[cnt]=y;ne[cnt]=he[x];he[x]=cnt++;}
int Pd(int x){return upper_bound(t+1,t+m+2,(nod){x,1e9})-t;}
int Pu(int x){return lower_bound(t+1,t+m+2,(nod){x,0})-t-1;}
void bud(int x,int l,int r)
{
id[x]=++tot;if(l==r){for(int i=0;i<s[l].size();i++) add(id[x],s[l][i]>n?s[l][i]-n:s[l][i]+n);return;}
int mid=(l+r)>>1;bud(x*2,l,mid);bud(x*2+1,mid+1,r);add(id[x],id[x*2]);add(id[x],id[x*2+1]);
}
void upd(int x,int l,int r,int b,int e,int v)
{
if(b>e) return;if(b<=l&&r<=e){add(v,id[x]);return;}int mid=(l+r)>>1;
if(b<=mid) upd(x*2,l,mid,b,e,v);if(e>mid) upd(x*2+1,mid+1,r,b,e,v);
}
void dfs(int x)
{
dfn[x]=low[x]=++I;in[x]=1;st[++tp]=x;
for(int i=he[x],y;~i;i=ne[i]) if(!dfn[y=to[i]]) dfs(y),low[x]=min(low[x],low[y]);else if(in[y]) low[x]=min(low[x],dfn[y]);
if(low[x]==dfn[x]){++nm;while(tp){sc[st[tp]]=nm;in[st[tp]]=0;if(st[tp--]==x) break;}}
}
int chk(int d)
{
memset(id,0,sizeof(id));tot=2*n;memset(he,-1,sizeof(he));cnt=0;bud(1,1,m);
for(int i=1;i<=n;i++) for(int j=0;j<2;j++)
{
upd(1,1,m,Pd(y[i][j]-d),x[i][j]-1,i+j*n),upd(1,1,m,x[i][j]+1,Pu(y[i][j]+d),i+j*n);
}
for(int i=1;i<=tot;i++) dfn[i]=low[i]=sc[i]=in[i]=0;I=tp=nm=0;
for(int i=1;i<=tot;i++) if(!dfn[i]) dfs(i);
for(int i=1;i<=n;i++) if(sc[i]==sc[i+n]) return 0;return 1;
}
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++) scanf("%d%d",&x[i][0],&x[i][1]),t[++m]=(nod){x[i][0],i},t[++m]=(nod){x[i][1],i+n};
memcpy(y,x,sizeof(x));sort(t+1,t+m+1);t[m+1]=(nod){1e9,1e9};
for(int i=1;i<=n;i++) for(int j=0;j<2;j++) x[i][j]=lower_bound(t+1,t+m+1,(nod){x[i][j],i+j*n})-t,s[x[i][j]].push_back(i+j*n);
for(int l=0,r=1e9,mid=(l+r)>>1;l<=r;mid=(l+r)>>1) if(chk(mid)) l=mid+1,g=mid;else r=mid-1;
printf("%d\n",g);
} | a.cc: In function 'int Pd(int)':
a.cc:7:52: error: narrowing conversion of '1.0e+9' from 'double' to 'int' [-Wnarrowing]
7 | int Pd(int x){return upper_bound(t+1,t+m+2,(nod){x,1e9})-t;}
| ^~~
a.cc: In function 'int main()':
a.cc:40:60: error: narrowing conversion of '1.0e+9' from 'double' to 'int' [-Wnarrowing]
40 | memcpy(y,x,sizeof(x));sort(t+1,t+m+1);t[m+1]=(nod){1e9,1e9};
| ^~~
|
s508525592 | p03802 | C++ | #include <bits/stdc++.h>
using namespace std;
#define N 10005
int n,m,rt,g,cnt,tot,nm,I,tp,x[N][2],y[N][2],id[N*10],he[N*10],ne[N*10],to[N*10],dfn[N*10],low[N*10],sc[N*10],in[N*10],st[N*10];vector<int>s[N*2];
struct nod{int x,d;friend int operator<(nod a,nod b){if(a.x!=b.x) return a.x<b.x;return a.d<b.d;}}t[N*2];
void add(int x,int y){to[cnt]=y;ne[cnt]=he[x];he[x]=cnt++;}
int Pd(int x){return upper_bound(t+1,t+m+2,(nod){x,1e9})-t;}
int Pu(int x){return lower_bound(t+1,t+m+2,(nod){x,0})-t-1;}
void bud(int x,int l,int r)
{
id[x]=++tot;if(l==r){for(int i=0;i<s[l].size();i++) add(id[x],s[l][i]>n?s[l][i]-n:s[l][i]+n);return;}
int mid=(l+r)>>1;bud(x*2,l,mid);bud(x*2+1,mid+1,r);add(id[x],id[x*2]);add(id[x],id[x*2+1]);
}
void upd(int x,int l,int r,int b,int e,int v)
{
if(b>e) return;if(b<=l&&r<=e){add(v,id[x]);return;}int mid=(l+r)>>1;
if(b<=mid) upd(x*2,l,mid,b,e,v);if(e>mid) upd(x*2+1,mid+1,r,b,e,v);
}
void dfs(int x)
{
dfn[x]=low[x]=++I;in[x]=1;st[++tp]=x;
for(int i=he[x],y;~i;i=ne[i]) if(!dfn[y=to[i]]) dfs(y),low[x]=min(low[x],low[y]);else if(in[y]) low[x]=min(low[x],dfn[y]);
if(low[x]==dfn[x]){++nm;while(tp){sc[st[tp]]=nm;in[st[tp]]=0;if(st[tp--]==x) break;}}
}
int chk(int d)
{
memset(id,0,sizeof(id));tot=2*n;memset(he,-1,sizeof(he));cnt=0;bud(1,1,m);
for(int i=1;i<=n;i++) for(int j=0;j<2;j++)
{
upd(1,1,m,Pd(y[i][j]-d),x[i][j]-1,i+j*n),upd(1,1,m,x[i][j]+1,Pu(y[i][j]+d),i+j*n);
}
for(int i=1;i<=tot;i++) dfn[i]=low[i]=sc[i]=in[i]=0;I=tp=nm=0;
for(int i=1;i<=tot;i++) if(!dfn[i]) dfs(i);
for(int i=1;i<=n;i++) if(sc[i]==sc[i+n]) return 0;return 1;
}
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++) scanf("%d%d",&x[i][0],&x[i][1]),t[++m]=(nod){x[i][0],i},t[++m]=(nod){x[i][1],i+n};
memcpy(y,x,sizeof(x));sort(t+1,t+m+1);t[m+1]=(nod){1e9,1e9};
for(int i=1;i<=n;i++) for(int j=0;j<2;j++) x[i][j]=lower_bound(t+1,t+m+1,(nod){x[i][j],i+j*n})-t,s[x[i][j]].push_back(i+j*n);
for(int l=0,r=1e9,mid=(l+r)>>1;l<=r;mid=(l+r)>>1) if(chk(mid)) l=mid+1,g=mid;else r=mid-1;
printf("%d\n",g);
} | a.cc: In function 'int Pd(int)':
a.cc:7:52: error: narrowing conversion of '1.0e+9' from 'double' to 'int' [-Wnarrowing]
7 | int Pd(int x){return upper_bound(t+1,t+m+2,(nod){x,1e9})-t;}
| ^~~
a.cc: In function 'int main()':
a.cc:40:60: error: narrowing conversion of '1.0e+9' from 'double' to 'int' [-Wnarrowing]
40 | memcpy(y,x,sizeof(x));sort(t+1,t+m+1);t[m+1]=(nod){1e9,1e9};
| ^~~
|
s810339308 | p03802 | C++ | #include <bits/stdc++.h>
#pragma GCC optimize("Ofast");
#define tm hdwusida
using namespace std;
int n;
int dm=0;
int x[10005], y[10005], f[20005];
vector<pair<int, pair<int, int> > > cor;
vector<int> adj[20005];
int low[20005], disc[20005];
bool instack[20005];
int lmao[10005][2];
int tm=0;
stack<int> st;
int find(int i)
{
return f[i]==i?f[i]:f[i]=find(f[i]);
}
void unionn(int u, int v)
{
f[find(u)]=find(v);
}
void scc(int u)
{
disc[u]=low[u]=++tm;
st.push(u);
instack[u] = true;
for(auto v:adj[u])
{
if(disc[v]==-1)
{
scc(v);
low[u]=min(low[u], low[v]);
}
else if(instack[v]==true)
{
low[u]=min(low[u], disc[v]);
}
}
if(low[u]==disc[u])
{
while(st.top()!=u)
{
int v=st.top();
unionn(u, v);
instack[v]=false;
st.pop();
}
instack[u]=false;
st.pop();
}
}
bool check(int v)
{
dm++;
tm=0;
for(int i=1; i<=2*n; i++)
{
f[i]=i;
low[i]=-1;
disc[i]=-1;
adj[i].clear();
}
for(int i=0; i<2*n; i++)
{
int now=cor[i].first, id=cor[i].second.first+n*cor[i].second.second;
for(int j=i-1; j>=0; j--)
{
if(cor[j].first<=now-v) break;
adj[id].push_back(cor[j].second.first+(cor[j].second.second^1)*n);
}
for(int j=i+1; j<2*n; j++)
{
if(cor[j].first>=now+v) break;
adj[id].push_back(cor[j].second.first+(cor[j].second.second^1)*n);
}
}
for(int i=1; i<=2*n; i++)
{
if(disc[i]==-1) scc(i);
}
for(int i=1; i<=n; i++)
{
if(find(i)==find(i+n)) return false;
}
return true;
}
signed main()
{
cin>>n;
for(int i=1; i<=n; i++)
{
cin>>x[i]>>y[i];
if(x[i]>y[i]) swap(x[i], y[i]);
cor.push_back({x[i], {i, 0}});
cor.push_back({y[i], {i, 1}});
}
sort(cor.begin(), cor.end());
int lo=0, hi=1e9;
while(lo<hi)
{
int mid=(lo+hi+1)/2;
if(check(mid))
{
lo=mid;
}
else
{
hi=mid-1;
}
}
cout<<lo;
} | a.cc:2:30: error: '#pragma GCC optimize' string is badly formed
2 | #pragma GCC optimize("Ofast");
| ^
|
s124228379 | p03802 | C++ | #include<bits/stdc++.h>
using namespace std;
const int N=100005,M=10000005;
int id1[N],id2[N],ne[M],fi[N],zz[M],low[N],dfn[N],l,from[N],tot,flag[N],Stack[N],x[N],y[N],f1[N],f2[N],n,cnt,num;
void jb(int x,int y){
ne[++tot]=fi[x];
fi[x]=tot;
zz[tot]=y;
}
void Tarjan(int x){
low[x]=dfn[x]=++l;
Stack[++tot]=x;
flag[x]=1;
for (int i=fi[x];i;i=ne[i]){
if (!dfn[zz[i]])Tarjan(zz[i]),low[x]=min(low[x],low[zz[i]]);
else if (flag[zz[i]])low[x]=min(low[x],dfn[zz[i]]);
}
if (low[x]==dfn[x]){
num++;
while (Stack[tot]!=x){
from[Stack[tot]]=num;
flag[Stack[tot]]=0;
tot--;
}
from[Stack[tot]]=num;
flag[Stack[tot]]=0;
tot--;
}
}
struct TTree{
int Flag;
struct Tree{
int l,r,id;
}T[N];
void build(int x,int l,int r){
T[x].l=l;T[x].r=r;
if (l==r){
if (Flag)T[x].id=f1[l]+n;
else T[x].id=f2[l];
return;
}
T[x].id=++cnt;
int mid=(l+r)/2;
build(x*2,l,mid);
build(x*2+1,mid+1,r);
}
void solve(int x){
if (T[x].l==T[x].r)return;
jb(T[x].id,T[x*2].id);jb(T[x].id,T[x*2+1].id);
solve(x*2);solve(x*2+1);
}
void insert(int x,int l,int r,int z){
if (T[x].l>r||l>T[x].r)return;
if (T[x].l>=l&&T[x].r<=r){
jb(z,T[x].id);
return;
}
insert(x*2,l,r,z);
insert(x*2+1,l,r,z);
}
}T[2];
int cmp1(int a,int b){
return x[a]<x[b];
}
int cmp2(int a,int b){
return y[a]<y[b];
}
int check(int dis){
memset(fi,0,sizeof fi);
memset(dfn,0,sizeof dfn);
tot=0;
T[0].solve();T[1].solve();
for (int i=2;i<=n;i++){
int l=1,r=i;
while (l<r){
int mid=(l+r)/2;
if (x[f1[mid]]<=x[f1[i]]-dis)l=mid+1;
else r=mid;
}
T[0].insert(1,l,i-1,f1[i]);
}
for (int i=1;i<n;i++){
int l=i,r=n;
while (l<r){
int mid=(l+r+1)/2;
if (x[f1[mid]]>=x[f1[i]]+dis)r=mid-1;
else l=mid;
}
T[0].insert(1,i+1,l,f1[i]);
}
for (int i=2;i<=n;i++){
int l=1,r=i;
while (l<r){
int mid=(l+r)/2;
if (y[f2[mid]]<=y[f2[i]]-dis)l=mid+1;
else r=mid;
}
T[1].insert(1,l,i-1,f2[i]+n);
}
for (int i=1;i<n;i++){
int l=i,r=n;
while (l<r){
int mid=(l+r+1)/2;
if (y[f2[mid]]>=y[f2[i]]+dis)r=mid-1;
else l=mid;
}
T[1].insert(1,i+1,l,f2[i]+n);
}
for (int i=1;i<=n;i++){
int l1=1,r1=n;
while (l1<r1){
int mid=(l1+r1)/2;
if (y[f2[mid]]>x[f1[i]]-dis)r1=mid;
else l1=mid+1;
}
int l2=1,r2=n;
while (l2<r2){
int mid=(l2+r2+1)/2;
if (y[f2[mid]]<x[f1[i]]+dis)l2=mid;
else r2=mid-1;
}
if (l1>l2)continue;
if (id2[f1[i]]>=l1&&id2[f1[i]]<=l2){
T[1].insert(1,l1,id2[f1[i]]-1,f1[i]);
T[1].insert(1,id2[f1[i]]+1,l2,f1[i]);
}
else T[1].insert(1,l1,l2,f1[i]);
}
for (int i=1;i<=n;i++){
int l1=1,r1=n;
while (l1<r1){
int mid=(l1+r1)/2;
if (x[f1[mid]]>y[f2[i]]-dis)r1=mid;
else l1=mid+1;
}
int l2=1,r2=n;
while (l2<r2){
int mid=(l2+r2+1)/2;
if (x[f1[mid]]<y[f2[i]]+dis)l2=mid;
else r2=mid-1;
}
if (l1>l2)continue;
if (id1[f2[i]]>=l1&&id1[f2[i]]<=l2){
T[0].insert(1,l1,id1[f2[i]]-1,f2[i]+n);
T[0].insert(1,id1[f2[i]]+1,l2,f2[i]+n);
}
else T[0].insert(1,l1,l2,f2[i]+n);
}
tot=l=num=0;
for (int i=1;i<=cnt;i++)
if (!dfn[i])Tarjan(i);
for (int i=1;i<=n;i++)
if (from[i]==from[n+i])return 0;
return 1;
}
int main(){
scanf("%d",&n);
for (int i=1;i<=n;i++)scanf("%d%d",&x[i],&y[i]);
for (int i=1;i<=n;i++)f1[i]=i,f2[i]=i;
sort(f1+1,f1+n+1,cmp1);
sort(f2+1,f2+n+1,cmp2);
for (int i=1;i<=n;i++)id1[f1[i]]=i,id2[f2[i]]=i;
cnt=2*n;
T[0].Flag=1;
T[0].build(1,1,n);
T[1].build(1,1,n);
int l=0,r=1e9;
while (l<r){
int mid=(l+r+1)/2;
if (check(mid))l=mid;
else r=mid-1;
}
printf("%d\n",l);
return 0;
}
| a.cc: In function 'int check(int)':
a.cc:72:19: error: no matching function for call to 'TTree::solve()'
72 | T[0].solve();T[1].solve();
| ~~~~~~~~~~^~
a.cc:47:14: note: candidate: 'void TTree::solve(int)'
47 | void solve(int x){
| ^~~~~
a.cc:47:14: note: candidate expects 1 argument, 0 provided
a.cc:72:32: error: no matching function for call to 'TTree::solve()'
72 | T[0].solve();T[1].solve();
| ~~~~~~~~~~^~
a.cc:47:14: note: candidate: 'void TTree::solve(int)'
47 | void solve(int x){
| ^~~~~
a.cc:47:14: note: candidate expects 1 argument, 0 provided
|
s127710756 | p03802 | C++ | #include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int N = 2e4+100;
const int INF = 1e9+1;
inline int read()
{
int x = 0 , f = 1 ; char c = getchar();
while(c < '0' || c > '9') { if(c == '-') f = -f ; c = getchar(); }
while(c >= '0' && c <= '9') x = x * 10 + c - '0' , c = getchar();
return x * f;
}
int n , cnt;
int head[N];
struct node{
int to , nex;
node(int to = 0 , int nex = 0):to(to) , nex(nex){}
}e[N*40000];
struct Node{
int val , id;
Node(int val = 0 , int id = 0):val(val) , id(id){}
bool operator < (const Node &A) const { return val < A.val; }
}a[N];
void add(int u , int v) { e[++cnt] = node(v , head[u]); head[u] = cnt; }
int dfn[N] , low[N] , sta[N] , col[N] , pos[N] , L[N] , R[N] , len, top , num , tot;
bool vis[N];
void Tarjan(int x)
{
dfn[x] = low[x] = ++tot; sta[++top] = x; vis[x] = true;
for(int i = head[x] ; i ; i = e[i].nex)
{
int to = e[i].to;
if(!dfn[to]) Tarjan(to) , low[x] = min(low[x] , low[to]);
else if(vis[to]) low[x] = min(low[x] , dfn[to]);
}
if(low[x] == dfn[x])
{
num++;
int t;
do{
t = sta[top--];
col[t] = num; vis[t] = false;
}while(t != x);
}
}
inline int Abs(int x) { return x < 0 ? -x : x; }
void Add(int l , int r , int to)
{
if(l > r) return;
if(pos[l] == pos[r])
{
for(int i = l ; i <= r ; ++i) add(a[i].id , to);
return ;
}
for(int i = l ; i <= R[pos[l]] ; ++i) add(a[i].id , to);
for(int i = L[pos[r]] ; i <= r ; ++i) add(a[i].id , to);
for(int i = pos[l] + 1 ; i <= pos[r] - 1 ; ++i) add(i + (n << 1) , to);
}
bool check(int k)
{
memset(dfn , 0 , sizeof dfn); memset(vis , false , sizeof vis);
memset(low , 0 , sizeof low); memset(col , 0 , sizeof col);
memset(head, 0 , sizeof head); tot = 0 , cnt = 0 , num = 0 , top = 0;
for(int i = 1 ; i <= pos[n<<1]; ++i)
for(int j = L[i] ; j <= R[i] ; ++j) add(i + (n << 1) , a[j].id);
for(int i = 1 ; i <= (n<<1) ; ++i)
{
int opt = a[i].id <= n ? a[i].id + n : a[i].id - n;
int l = lower_bound(a + 1 , a + 1 + (n << 1) , Node(a[i].val - k , i)) - a;
int r = lower_bound(a + 1 , a + 1 + (n << 1) , Node(a[i].val + k , i)) - a;
int lr = lower_bound(a + 1 , a + 1 + (n << 1) , a[i] ) - a , rr = lr;
while(a[lr].val == a[i].val) lr--;
while(a[rr].val == a[i].val) rr++;
while(a[i].val - a[l].val > k && l <= r) l++;
while(a[r].val - a[i].val > k && l <= r) r--;
if(!(l <= r)) continue;
for(int j = lr + 1 ; j <= rr - 1 ; ++j) if(a[j].id != a[i].id) add(a[j].id , opt);
Add(l , lr , opt); Add(rr , r , opt);
}
for(int i = 1 ; i <= (n<<1) ; ++i) if(!dfn[i]) Tarjan(i);
for(int i = 1 ; i <= n ; ++i) if(col[i] == col[i+n]) return false;
return true;
}
// 原节点 1 ~ 2n 块 2n + 1 ~ 2n + pos[n]
int main()
{
// freopen("disaster.in" , "r" , stdin);
// freopen("disaster.out" , "w" , stdout);
n = read(); len = sqrt(n << 1);
for(int i = 1 ; i <= n ; ++i) a[i] = Node(read() , i) , a[i+n] = Node(read() , i+n);
sort(a + 1 , a + 1 + (n << 1));
for(int i = 1 ; i <= (n << 1); ++i) pos[i] = (i-1) / len + 1;
for(int i = 1 ; i <= pos[n<<1] ; ++i) L[i] = (i-1) * len + 1 , R[i] = min(i * len , n << 1 );
int l = 1 , r = INF , ans = -1;
while( l <= r )
{
int mid = (l + r) >> 1;
if(check(mid)) ans = mid , l = mid + 1;
else r = mid - 1;
}
cout << ans+1 << endl;
fclose(stdin);
fclose(stdout);
return 0;
}
/*
3
1 2
3 4
5 6
*/ | /tmp/cczN2fu3.o: in function `Tarjan(int)':
a.cc:(.text+0x92): relocation truncated to fit: R_X86_64_PC32 against symbol `tot' defined in .bss section in /tmp/cczN2fu3.o
a.cc:(.text+0x9b): relocation truncated to fit: R_X86_64_PC32 against symbol `tot' defined in .bss section in /tmp/cczN2fu3.o
a.cc:(.text+0xa1): relocation truncated to fit: R_X86_64_PC32 against symbol `tot' defined in .bss section in /tmp/cczN2fu3.o
a.cc:(.text+0xb6): relocation truncated to fit: R_X86_64_PC32 against symbol `low' defined in .bss section in /tmp/cczN2fu3.o
a.cc:(.text+0xcd): relocation truncated to fit: R_X86_64_PC32 against symbol `low' defined in .bss section in /tmp/cczN2fu3.o
a.cc:(.text+0xe5): relocation truncated to fit: R_X86_64_PC32 against symbol `dfn' defined in .bss section in /tmp/cczN2fu3.o
a.cc:(.text+0xf1): relocation truncated to fit: R_X86_64_PC32 against symbol `top' defined in .bss section in /tmp/cczN2fu3.o
a.cc:(.text+0xfa): relocation truncated to fit: R_X86_64_PC32 against symbol `top' defined in .bss section in /tmp/cczN2fu3.o
a.cc:(.text+0x100): relocation truncated to fit: R_X86_64_PC32 against symbol `top' defined in .bss section in /tmp/cczN2fu3.o
a.cc:(.text+0x112): relocation truncated to fit: R_X86_64_PC32 against symbol `sta' defined in .bss section in /tmp/cczN2fu3.o
a.cc:(.text+0x121): additional relocation overflows omitted from the output
collect2: error: ld returned 1 exit status
|
s024145716 | p03802 | C++ | include<bits/stdc++.h>
#define rg register
#define file(x) freopen(x".in","r",stdin);freopen(x".out","w",stdout);
using namespace std;
int read(){
int x=0,f=1;char c=getchar();
while(c<'0'||c>'9') f=(c=='-')?-1:1,c=getchar();
while(c>='0'&&c<='9') x=x*10+c-48,c=getchar();
return f*x;
}
struct node{
int x,y,id;
}a[2000001];
bool cmp(const node & a , const node & b ){
if(a.x==b.x) return a.y<b.y;
return a.x<b.x;
}
int n,m;
int vis[200001];
bool check(int x){
for(int j=1;j<=1;j++){
int now=a[j].x,flag=0;
memset(vis,0,sizeof(vis));
vis[a[j].id]=1;
for(int i=j+1;i<=n;i++){
if(vis[a[i].id]) continue;
if(now+x<=a[i].x)
now=a[i].x;
else continue;
vis[a[i].id]=1;
}
for(int i=1;i<=n/2;i++)
if(!vis[i])
flag=1;
if(!flag) return 1;
}
return 0;
}
int A[1001][2],c[1001],d[1001],maxx;
void dfs(int x){
if(x==n+1){
for(int i=1;i<=n;i++)
d[i]=A[i][c[i]];
sort(d+1,d+1+n);
int minx=2147483647;
for(int i=2;i<=n;i++)
minx=min(d[i]-d[i-1],minx);
maxx=max(minx,maxx);
return ;
}
for(int i=0;i<=1;i++)
c[x]=i,dfs(x+1);
}
int main(){
//file("");
n=read();
for(int i=1;i<=n;i++)
A[i][0]=a[i].x=read(),A[i][1]=a[i].y=a[i+n].x=read(),a[i].id=i,a[i+n].id=i;
if(n<=22) dfs(1),cout<<maxx,exit(0);
// cout<<check(17);
// exit(0);
int l=0,r=100000000,ans;
n*=2;
sort(a+1,a+1+n,cmp);
while(l<=r){
int mid=(l+r)>>1;
if(check(mid)) l=mid+1,ans=mid;
else r=mid-1;
}
cout<<ans;
return 0;
}
| a.cc:1:1: error: 'include' does not name a type
1 | include<bits/stdc++.h>
| ^~~~~~~
a.cc: In function 'int read()':
a.cc:6:24: error: 'getchar' was not declared in this scope
6 | int x=0,f=1;char c=getchar();
| ^~~~~~~
a.cc:1:1: note: 'getchar' is defined in header '<cstdio>'; this is probably fixable by adding '#include <cstdio>'
+++ |+#include <cstdio>
1 | include<bits/stdc++.h>
a.cc: In function 'bool check(int)':
a.cc:23:17: error: 'memset' was not declared in this scope
23 | memset(vis,0,sizeof(vis));
| ^~~~~~
a.cc:1:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
+++ |+#include <cstring>
1 | include<bits/stdc++.h>
a.cc: In function 'void dfs(int)':
a.cc:45:17: error: 'sort' was not declared in this scope; did you mean 'short'?
45 | sort(d+1,d+1+n);
| ^~~~
| short
a.cc:48:30: error: 'min' was not declared in this scope; did you mean 'minx'?
48 | minx=min(d[i]-d[i-1],minx);
| ^~~
| minx
a.cc:49:22: error: 'max' was not declared in this scope; did you mean 'maxx'?
49 | maxx=max(minx,maxx);
| ^~~
| maxx
a.cc: In function 'int main()':
a.cc:61:26: error: 'cout' was not declared in this scope
61 | if(n<=22) dfs(1),cout<<maxx,exit(0);
| ^~~~
a.cc:61:37: error: 'exit' was not declared in this scope
61 | if(n<=22) dfs(1),cout<<maxx,exit(0);
| ^~~~
a.cc:1:1: note: 'exit' is defined in header '<cstdlib>'; this is probably fixable by adding '#include <cstdlib>'
+++ |+#include <cstdlib>
1 | include<bits/stdc++.h>
a.cc:66:9: error: 'sort' was not declared in this scope; did you mean 'short'?
66 | sort(a+1,a+1+n,cmp);
| ^~~~
| short
a.cc:72:9: error: 'cout' was not declared in this scope
72 | cout<<ans;
| ^~~~
|
s648424615 | p03802 | C++ | include<bits/stdc++.h>
#define rg register
#define file(x) freopen(x".in","r",stdin);freopen(x".out","w",stdout);
using namespace std;
int read(){
int x=0,f=1;char c=getchar();
while(c<'0'||c>'9') f=(c=='-')?-1:1,c=getchar();
while(c>='0'&&c<='9') x=x*10+c-48,c=getchar();
return f*x;
}
struct node{
int x,y,id;
}a[2000001];
bool cmp(const node & a , const node & b ){
if(a.x==b.x) return a.y<b.y;
return a.x<b.x;
}
int n,m;
int vis[200001];
bool check(int x){
for(int j=1;j<=1;j++){
int now=a[j].x,flag=0;
memset(vis,0,sizeof(vis));
vis[a[j].id]=1;
for(int i=j+1;i<=n;i++){
if(vis[a[i].id]) continue;
if(now+x<=a[i].x)
now=a[i].x;
else continue;
vis[a[i].id]=1;
}
for(int i=1;i<=n/2;i++)
if(!vis[i])
flag=1;
if(!flag) return 1;
}
return 0;
}
int A[1001][2],c[1001],d[1001],maxx;
void dfs(int x){
if(x==n+1){
for(int i=1;i<=n;i++)
d[i]=A[i][c[i]];
sort(d+1,d+1+n);
int minx=2147483647;
for(int i=2;i<=n;i++)
minx=min(d[i]-d[i-1],minx);
maxx=max(minx,maxx);
return ;
}
for(int i=0;i<=1;i++)
c[x]=i,dfs(x+1);
}
int main(){
//file("");
n=read();
for(int i=1;i<=n;i++)
A[i][0]=a[i].x=read(),A[i][1]=a[i].y=a[i+n].x=read(),a[i].id=i,a[i+n].id=i;
if(n<=22) dfs(1),cout<<maxx,exit(0);
// cout<<check(17);
// exit(0);
int l=0,r=100000000,ans;
n*=2;
sort(a+1,a+1+n,cmp);
while(l<=r){
int mid=(l+r)>>1;
if(check(mid)) l=mid+1,ans=mid;
else r=mid-1;
}
cout<<ans;
return 0;
} | a.cc:1:1: error: 'include' does not name a type
1 | include<bits/stdc++.h>
| ^~~~~~~
a.cc: In function 'int read()':
a.cc:6:24: error: 'getchar' was not declared in this scope
6 | int x=0,f=1;char c=getchar();
| ^~~~~~~
a.cc:1:1: note: 'getchar' is defined in header '<cstdio>'; this is probably fixable by adding '#include <cstdio>'
+++ |+#include <cstdio>
1 | include<bits/stdc++.h>
a.cc: In function 'bool check(int)':
a.cc:23:17: error: 'memset' was not declared in this scope
23 | memset(vis,0,sizeof(vis));
| ^~~~~~
a.cc:1:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
+++ |+#include <cstring>
1 | include<bits/stdc++.h>
a.cc: In function 'void dfs(int)':
a.cc:45:17: error: 'sort' was not declared in this scope; did you mean 'short'?
45 | sort(d+1,d+1+n);
| ^~~~
| short
a.cc:48:30: error: 'min' was not declared in this scope; did you mean 'minx'?
48 | minx=min(d[i]-d[i-1],minx);
| ^~~
| minx
a.cc:49:22: error: 'max' was not declared in this scope; did you mean 'maxx'?
49 | maxx=max(minx,maxx);
| ^~~
| maxx
a.cc: In function 'int main()':
a.cc:61:26: error: 'cout' was not declared in this scope
61 | if(n<=22) dfs(1),cout<<maxx,exit(0);
| ^~~~
a.cc:61:37: error: 'exit' was not declared in this scope
61 | if(n<=22) dfs(1),cout<<maxx,exit(0);
| ^~~~
a.cc:1:1: note: 'exit' is defined in header '<cstdlib>'; this is probably fixable by adding '#include <cstdlib>'
+++ |+#include <cstdlib>
1 | include<bits/stdc++.h>
a.cc:66:9: error: 'sort' was not declared in this scope; did you mean 'short'?
66 | sort(a+1,a+1+n,cmp);
| ^~~~
| short
a.cc:72:9: error: 'cout' was not declared in this scope
72 | cout<<ans;
| ^~~~
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.