Sort by

recency

|

43 Discussions

|

  • + 0 comments

    This is the solution but I need a Efficient one

    def solve(s):
        j=0
        for i in set(combinations(s,3)):
            if(i[0]<i[1] and i[1]<i[2]):
                j+=1
        return j
    

    Time complexity is too high

  • + 0 comments

    How to use triplet in a sentence. strong taweez for love

  • + 0 comments

    C# solution based on editorial (witch does not work out of the box)

    public class BIT  
    {
    	private readonly long _max;
    	private readonly long[] _tree;
    
    	public BIT(long max)
    	{
    		_max = max;
    		_tree = new long[max];
    	}
    
    	public long get(int idx)
    	{
    		return query(idx) - query(idx - 1);
    	}
    
    	public void set(int idx, long val)
    	{
    		long curr = get(idx);
    		while (idx <= _max)
    		{
    			_tree[idx] += val-curr;
    			idx += (idx & -idx);
    		}
    	}
    
    	public long query(int idx)
    	{
    		long sum = 0;
    		while (idx > 0)
    		{
    			if (idx < _max)
    			{
    				sum += _tree[idx];
    			}
    
    			idx -= (idx & -idx);
    		}
    
    		return sum;
    	}
    }
    
    public static long solve(List<long> arr)
    {
    	var max = arr.Count;
    	long[] h = new long[max];
    	var S = new SortedSet<long>();
    	var m = new Dictionary<long, long>();
    	var a = new BIT(max);
    	var b = new BIT(max);
    	var c = new BIT(max);
    
    	foreach (var l in arr)
    	{
    		S.Add(l);
    	}
    
    	long cnt = 1;
    	foreach (var l in S)
    	{
    		m.Add(l, cnt++);
    	}
    
    	for (int i = 0; i < arr.Count; i++)
    	{
    		int indx = Convert.ToInt32(m[arr[i]]);
    		h[i] = m[arr[i]];
    		a.set(indx, 1);
    		b.set(indx, a.query(indx - 1));
    		c.set(indx, b.query(indx - 1));
    	}
    
    	return c.query(max);
    
    }
    
  • + 0 comments

    Python3 solution

    n = int(input())
    num = sorted([(int(x), (i + 1)) for i, x in enumerate(input().split())])
    m = n + 1
    s = [[0] * (m + 1), [0] * (m + 1), [0] * (m + 1), [0] * (m + 1)]
    s[0][0] = 1
    
    def Sum(s, n):
        ret = s[0]
        while n > 0:
            ret += s[n]
            n = n ^ (n & (~n + 1))
        return ret
    
    def Update(s, n, v):
        while n <= m:
            s[n] += v
            n += n & (~n + 1)
    
    for i, (n, id) in enumerate(num):
        if i and num[i - 1][0] == num[i][0]:
            continue
        process = [(n, id)]
        if i + 1 < len(num) and num[i][0] == num[i + 1][0]:
            process.append(num[i + 1])
        for state in (3, 2, 1):
            values = []
            for n, id in process:
                values.append(Sum(s[state - 1], id - 1))
            if len(values) > 1: values[1] -= values[0]
            for j, (n, id) in enumerate(process):
                Update(s[state], id, values[j])
    print(Sum(s[3], m - 1))
    
  • + 0 comments

    for complete solution in java c++ and c programming search for programs.programmingoneonone.com on google